Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16427
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <pedro.h.souto@gmail.com> |
| 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; 'newbie': 0.03; 'main()': 0.05; 'question:': 0.07; 'python': 0.08; 'scripts': 0.09; '__name__': 0.09; 'message-----': 0.12; "'__main__':": 0.16; '(do': 0.16; 'intended.': 0.16; 'main():': 0.16; 'practice?': 0.16; 'received:209.85.213.174': 0.16; 'received:mail- yx0-f174.google.com': 0.16; 'shambhu': 0.16; 'this:': 0.16; 'subject:question': 0.17; '(i.e.': 0.17; 'wrote:': 0.18; '(which': 0.19; 'seems': 0.20; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'collins': 0.23; 'module,': 0.23; 'module': 0.26; 'function': 0.27; 'import': 0.27; 'code,': 0.27; 'variable': 0.28; 'coding': 0.28; 'depends': 0.28; 'work.': 0.28; 'script': 0.28; 'case).': 0.30; 'imported': 0.30; 'thanks': 0.31; 'quite': 0.32; 'hi,': 0.32; 'message-id:@gmail.com': 0.33; 'header:User-Agent:1': 0.33; 'done': 0.34; 'to:addr:python-list': 0.34; 'subject:': 0.34; 'end.': 0.34; 'running': 0.35; 'however,': 0.36; 'starting': 0.36; 'sent:': 0.36; 'beginning': 0.36; 'but': 0.37; 'received:192': 0.37; 'received:google.com': 0.37; 'not,': 0.37; 'received:209.85': 0.38; 'put': 0.38; 'i.e.': 0.39; 'programming.': 0.39; 'from:': 0.39; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'received:192.168': 0.40; 'matter': 0.61; 'total': 0.61; 'your': 0.61; 'results': 0.63; 'bear': 0.64; 'for).': 0.91; 'subject:Best': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=CnRETLc2p7IbElKEu8pH6IpF2RmvsCEnViIyhI2bJM0=; b=IOgC8IVUbLKzC49r0BBhnaJd25GRRyFonen6eQxfGTnLqC/6myWXezNgkVly7qs/0R 7/CvTML5XZW8S5KED88Gbe7DdxxyRNpHYYGVr8Ph5byEdhi3QrAvdGWEPqRDuBfGLRh0 /hGHzvxKyx5ZYX+IVJPvylWM3bEOWkQZw1I0I= |
| Date | Wed, 30 Nov 2011 09:36:15 -0200 |
| From | "Pedro Henrique G. Souto" <pedro.h.souto@gmail.com> |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20111105 Thunderbird/8.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Total newbie question: Best practice |
| References | <jb3e06$37h$1@dont-email.me> <408F64D89899604FB24015E64E10490C179CAB10@KCHJEXMB02.kpit.com> |
| In-Reply-To | <408F64D89899604FB24015E64E10490C179CAB10@KCHJEXMB02.kpit.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3153.1322653011.27778.python-list@python.org> (permalink) |
| Lines | 55 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1322653011 news.xs4all.nl 6958 [2001:888:2000:d::a6]:56999 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:16427 |
Show key headers only | View raw
On 30/11/2011 06:50, Shambhu Rajak wrote:
> Collins Congratulations for your first step into Python Programming.
> You can call them script or programs(not necessarily but depends on what your coding for).
> Yaa..it's always a good practice to call it through main(), but it doesn't really matter you
> can call the method in way....
>
> Regards,
> Shambhu
>
> -----Original Message-----
> From: Colin Higwell [mailto:colinh@somewhere.invalid]
> Sent: 30/11/2011 1:37 AM
> To: python-list@python.org
> Subject: Total newbie question: Best practice
>
> Hi,
>
> I am just starting to learn Python (I have been at it only a few hours),
> so please bear with me. I have a few very small scripts (do you call them
> scripts or programs?) which work properly, and produce the results
> intended.
>
> However, they are monolithic in nature; i.e. they begin at the beginning
> and finish at the end. Having done a little reading, I note that it seems
> to be quite common to have a function main() at the start (which in turn
> calls other functions as appropriate), and then to call main() to do the
> work.
>
> Is that standard best practice?
>
> Thanks
Congratulations on becoming a Pythonist!
Like Shambhu said, it doesn't matter where do you put the code, but is
interesting to have a main() function when you have a program, and you
want to differentiate if it is running directly (i.e. python program.py)
or if it is running as a module, imported by other program (i.e. import
program).
To do so, you do this:
main():
# blablabla
if __name__ == '__main__':
main()
If the program is running directly, the variable __name__ will be
'__main__', if not, __name__ will be the name of the module ('program',
in this case).
Att;
Pedro
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Total newbie question: Best practice Colin Higwell <colinh@somewhere.invalid> - 2011-11-29 20:06 +0000
Re: Total newbie question: Best practice Arnaud Delobelle <arnodel@gmail.com> - 2011-11-29 20:34 +0000
Re: Total newbie question: Best practice Neil Cerutti <neilc@norwich.edu> - 2011-11-29 21:12 +0000
Re: Total newbie question: Best practice Chris Angelico <rosuav@gmail.com> - 2011-11-30 07:36 +1100
Re: Total newbie question: Best practice Dave Angel <d@davea.name> - 2011-11-29 16:57 -0500
Re: Total newbie question: Best practice Colin Higwell <colinh@somewhere.invalid> - 2011-11-29 23:08 +0000
RE: Total newbie question: Best practice Shambhu Rajak <Shambhu.Rajak@kpitcummins.com> - 2011-11-30 08:50 +0000
Re: Total newbie question: Best practice "Pedro Henrique G. Souto" <pedro.h.souto@gmail.com> - 2011-11-30 09:36 -0200
csiph-web