On Sep 4, 5:56 am, "Jan Kaliszewski" wrote:
> 04-09-2009 o 08:37:43 r wrote:
>
> > Why use a nested function when you already *in* main?
>
> I understand you name global scope as 'main'. But (independently
> of using the __main__ idiom and so on) it is still good idea not to
> place to much code
Carl Banks wrote:
> Sorry, alex, unfortunately you are wrong, although it's understandable
> that you've missed this.
> [...]
> The speedup comes because local lookups are much faster. Accessing a
> local is a simple index operation, and a nonlocal is a pointer deref
> or two, then an indexing.
Carl Banks wrote:
On Sep 3, 11:39 pm, Simon Brunning wrote:
2009/9/4 Manuel Graune :
How come the main()-idiom is not "the standard way" of writing a
python-program (like e.g. in C)?
Speaking for myself, it *is* the standard way to structure a script. I
find it more readable, since I can put
On Fri, 2009-09-04 at 22:55 +1000, Ben Finney wrote:
> * having a module that can be imported without side effects helps
> select
> pieces of the module's functionality
>
> * any module should be importable without side effects to make it
> easier
> to run unit tests for that module
>
+1
--
"Jan Kaliszewski" writes:
> I understand you name global scope as 'main'. But (independently of
> using the __main__ idiom and so on) it is still good idea not to place
> to much code in the global scope but to place your app-logic code in
> functions -- because, as we noted:
>
> * in practice it
Manuel Graune wrote:
[ ... ]
> thanks for your answer. What you are explaining is exactly why I tried
> it in the first place. I'm just wondering why (this is my impression,
> not necessaryly the reallity) none of the recommended texts on python
> put this in the first chapters. Instead - if it is
04-09-2009 o 08:37:43 r wrote:
Why use a nested function when you already *in* main?
I understand you name global scope as 'main'. But (independently
of using the __main__ idiom and so on) it is still good idea not to
place to much code in the global scope but to place your app-logic
code in
So yes, depending on the nature of your code, its quite conceivable to
find distinct performance differences between code using the __main__
idiom and code without.
But -- it should be emphasized -- it's faster thanks to running code
(an doing name lookups) within a function, and *not* thanks to
On Sep 3, 11:39 pm, Simon Brunning wrote:
> 2009/9/4 Manuel Graune :
>
> > How come the main()-idiom is not "the standard way" of writing a
> > python-program (like e.g. in C)?
>
> Speaking for myself, it *is* the standard way to structure a script. I
> find it more readable, since I can put my ma
On Sep 3, 11:55 pm, alex23 wrote:
> Sean DiZazzo wrote:
> > What are you using to test the scripts? I could be completely wrong,
> > but I find it hard to believe that the second version is much (if any)
> > faster than the first. Then again, I don't know much about the
> > internals...
>
> Sor
Sean DiZazzo writes:
> I'm trying to come up with an answer for you, but I can't...
>
> The if __name__ == "__main__": idiom *is* the standard way to write
> python programs, but it's not there to speed up programs. It's there
> so that your program can be executed differently whether it is call
On Sep 3, 11:55 pm, alex23 wrote:
> Sean DiZazzo wrote:
> > What are you using to test the scripts? I could be completely wrong,
> > but I find it hard to believe that the second version is much (if any)
> > faster than the first. Then again, I don't know much about the
> > internals...
>
> Sor
Sean DiZazzo wrote:
> What are you using to test the scripts? I could be completely wrong,
> but I find it hard to believe that the second version is much (if any)
> faster than the first. Then again, I don't know much about the
> internals...
Sorry, Sean, unfortunately you are wrong, although
2009/9/4 Manuel Graune :
> How come the main()-idiom is not "the standard way" of writing a
> python-program (like e.g. in C)?
Speaking for myself, it *is* the standard way to structure a script. I
find it more readable, since I can put my main function at the very
top where it's visible, with the
On Sep 4, 12:55 am, Manuel Graune wrote:
(snip)
> How come the main()-idiom is not "the standard way" of writing a
> python-program (like e.g. in C)?
Why use a nested function when you already *in* main? thats like
declaring variables when your compiler could just use some simple
logic...
'2.7'
On Sep 3, 10:55 pm, Manuel Graune wrote:
> Hello everyone,
>
> the standard structure of a python-program which is taught in all of
> the books I on python I read by now is simply something like:
>
> #!/usr/bin/python
> print "Hello, world!"
> ^D
>
> While reading about structuring a larger code-b
Hello everyone,
the standard structure of a python-program which is taught in all of
the books I on python I read by now is simply something like:
#!/usr/bin/python
print "Hello, world!"
^D
While reading about structuring a larger code-base, unit-testing, etc
I stumbled on the idiom
#!/usr/bin
17 matches
Mail list logo