Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101456
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Newsgroups | comp.lang.python |
| Subject | Re: When I need classes? |
| Date | Mon, 11 Jan 2016 13:57:41 +1100 |
| Lines | 29 |
| Message-ID | <mailman.1.1452481599.13488.python-list@python.org> (permalink) |
| References | <56927291.6010009@gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii; format=flowed |
| X-Trace | news.uni-berlin.de DgjuW7Ea4y9bxJeZSfDNFwk9xH/67nhHC9ft2PO50Vhg== |
| Return-Path | <cameron@cskk.homeip.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'needed,': 0.05; '(b)': 0.07; '__name__': 0.07; 'classes.': 0.07; 'main()': 0.07; 'logic': 0.09; 'def': 0.13; 'variables': 0.15; "'__main__':": 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'simpson': 0.16; 'wrote:': 0.16; 'later': 0.16; 'subject:need': 0.18; '(a)': 0.22; 'aspect': 0.22; 'cheers,': 0.22; 'defined': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'script': 0.25; 'header:User- Agent:1': 0.26; 'behaviour': 0.29; 'putting': 0.30; 'another': 0.32; "can't": 0.32; 'michael': 0.33; 'avoiding': 0.33; "i'll": 0.33; 'structure': 0.34; 'but': 0.36; 'development.': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'received:localdomain': 0.38; 'speak': 0.38; 'to:addr:python.org': 0.40; 'where': 0.40; 'easy': 0.60; 'introduction': 0.63; 'cameron': 0.66; 'here': 0.66; 'as:': 0.79; '>if': 0.84; 'subject:When': 0.84 |
| Content-Disposition | inline |
| In-Reply-To | <56927291.6010009@gmail.com> |
| User-Agent | Mutt/1.5.24 (2015-08-30) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:101456 |
Show key headers only | View raw
On 10Jan2016 08:02, Michael Torrie <torriem@gmail.com> wrote:
>I can't speak to Flask or any other web development. But for simple
>scripts, I'll start out with no classes. Just functions as needed, and
>some main logic. I always use the idiom:
>
>if __name__ == '__main__':
> # do main logic here
>
>This way I can import functions defined in this script into another
>script later if I want.
I always structure this aspect as:
... at or near top of script ...
def main(argv):
... do main logic here ...
... at bottom ...
if __name__ == '__main__':
sys.exit(main(sys.argv))
This has the benefits of (a) putting the main program at the top where it is
easy to see/find and (b) avoiding accidently introduction of dependence on
global variables - because verything is inside main() it has the same behaviour
as any other function.
Cheers,
Cameron Simpson <cs@zip.com.au>
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: When I need classes? Cameron Simpson <cs@zip.com.au> - 2016-01-11 13:57 +1100 Re: When I need classes? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2016-01-11 07:31 +0000
csiph-web