[EMAIL PROTECTED] wrote:
> [EMAIL PROTECTED] wrote:
>> I think I read a suggestion somewhere to wrap the code where a Python
>> script starts in a main() function, so one has
>
>
>
>> What are the advantages of doing this?
>
> Others have stated all the good ones, so I'll state a slightly dumbe
[EMAIL PROTECTED] wrote:
> I think I read a suggestion somewhere to wrap the code where a Python
> script starts in a main() function, so one has
> What are the advantages of doing this?
Others have stated all the good ones, so I'll state a slightly dumber
one for us part time amateur hackers :
Steve Holden wrote:
> [EMAIL PROTECTED] wrote:
>> I think I read a suggestion somewhere to wrap the code where a Python
>> script starts in a main() function, so one has
>>
>> def main():
>> print "hi"
>>
>> main()
>>
>> instead of
>>
>> print "hi"
>>
>> What are the advantages of doing this?
>
Diez B. Roggisch wrote:
> Interesting. How is the index computed? I would have assumed that locals()
> is somehow used, which is a dicht.
>
> I can imagine enumerating left-hand-side names and trying to replace their
> occurence with the index, falling back to the name if that is not
> possible/t
In <[EMAIL PROTECTED]>, Paul Rubin wrote:
> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
>> > Python stores local variables in an indexed array, but globals in a
>> > dictionary. Looking things up by index is faster than looking them up by
>> > name.
>>
>> Interesting. How is the index computed
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> > Python stores local variables in an indexed array, but globals in a
> > dictionary. Looking things up by index is faster than looking them up by
> > name.
>
> Interesting. How is the index computed? I would have assumed that locals()
> is somehow
Fredrik Lundh wrote:
> "Diez B. Roggisch" wrote:
>
>>> There is another secondary advantage: the code inside a function runs
>>> faster (something related is true for C programs too). Usually this
>>> isn't important, but for certain programs they can go 20%+ faster.
>>
>> I totally fail to see w
Diez B. Roggisch wrote:
> [EMAIL PROTECTED] wrote:
>
>> Others have already told you the most important things.
>>
>> There is another secondary advantage: the code inside a function runs
>> faster (something related is true for C programs too). Usually this
>> isn't important, but for certain p
"Diez B. Roggisch" wrote:
>> There is another secondary advantage: the code inside a function runs
>> faster (something related is true for C programs too). Usually this
>> isn't important, but for certain programs they can go 20%+ faster.
>
> I totally fail to see why that should be the case - fo
On 9/19/06, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
> I totally fail to see why that should be the case - for python as well as
> for C.
If you put your code into a main() function, all the names that it
binds are in the function's local scope, whereas if the code is in the
module's top level
[EMAIL PROTECTED] wrote:
> Others have already told you the most important things.
>
> There is another secondary advantage: the code inside a function runs
> faster (something related is true for C programs too). Usually this
> isn't important, but for certain programs they can go 20%+ faster.
Another advantage is that you can catch all the unhandled exceptions of
the entire program (it they occurs) by doing something like this:
def another_call():
raise SomeUnexpectedException # it will be catched in '__main__'
def call():
another_call()
def run():
call()
in __name__ =
On 18 Sep 2006 14:38:12 -0700,
[EMAIL PROTECTED] wrote:
> ... There is another secondary advantage: the code inside a function
> runs faster (something related is true for C programs too). Usually
> this isn't important, but for certain
Steve Holden <[EMAIL PROTECTED]> writes:
> [EMAIL PROTECTED] wrote:
> > I think I read a suggestion somewhere to wrap the code where a
> > Python script starts in a main() function
> > [...]
> > What are the advantages of doing this?
> >
> Guido van Rossum himself can tell you:
>http://www.ar
Others have already told you the most important things.
There is another secondary advantage: the code inside a function runs
faster (something related is true for C programs too). Usually this
isn't important, but for certain programs they can go 20%+ faster.
Bye,
bearophile
--
http://mail.pyt
[EMAIL PROTECTED] wrote:
> I think I read a suggestion somewhere to wrap the code where a Python
> script starts in a main() function, so one has
>
> def main():
> print "hi"
>
> main()
>
> instead of
>
> print "hi"
>
> What are the advantages of doing this?
>
Guido van Rossum himself can
[EMAIL PROTECTED] wrote:
> I think I read a suggestion somewhere to wrap the code where a Python
> script starts in a main() function, so one has
>
> def main():
> print "hi"
>
> main()
>
> instead of
>
> print "hi"
>
> What are the advantages of doing this?
Refine this to:
def main():
On 18 Sep 2006 12:40:00 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I think I read a suggestion somewhere to wrap the code where a Python
> script starts in a main() function, so one has
>
> def main():
> print "hi"
>
> main()
>
> instead of
>
> print "hi"
>
> What are the advantages
[EMAIL PROTECTED] wrote:
> I think I read a suggestion somewhere to wrap the code where a Python
> script starts in a main() function, so one has
>
> def main():
> print "hi"
>
> main()
>
> instead of
>
> print "hi"
>
> What are the advantages of doing this?
I'm sure there are other reasons,
I think I read a suggestion somewhere to wrap the code where a Python
script starts in a main() function, so one has
def main():
print "hi"
main()
instead of
print "hi"
What are the advantages of doing this?
--
http://mail.python.org/mailman/listinfo/python-list
20 matches
Mail list logo