On 12/11/2013 5:26 AM, Ben Finney wrote:
Better design is to make the argument list a parameter to the ‘main’
function; this allows constructing an argument list specially for
calling that function, without ‘main’ needing to know the difference.
You'll also want to catch SystemExit and return t
On Thu, Dec 12, 2013 at 2:42 AM, bob gailer wrote:
> It also ensures that the defining all the classes and functions happens
> before referencing them (less "bookkeeping" for me).
>
> These two allow me to write the main program first, and follow it with all
> the global stuff.
I prefer define-be
On 12/11/2013 4:55 AM, JL wrote:
What is the advantage to using a main()?
In addition to what's been said I add:
It separates all the global activities: defining of functions and
classes, importing modules, etc. from the "doing" the actual task of the
program.
It also ensures that the defin
On Wednesday, December 11, 2013 7:47:34 PM UTC+5:30, Roy Smith wrote:
> JL wrote:
> > Python scripts can run without a main(). What is the advantage to using a
> > main()? Is it necessary to use a main() when the script uses command line
> > arguments? (See script below)
> > #!/usr/bin/python
In article ,
mar...@letterboxes.org wrote:
> I would agree with the previous post but also add that I've stopped
> calling the main function "main()" and usually give it a more
> descriptive name, such as "bake_cookies()" or whatever. I think that
> that makes it clearer what it's doing when use
In article <32615c9a-b983-4399-bb55-6df6c230f...@googlegroups.com>,
JL wrote:
> Python scripts can run without a main(). What is the advantage to using a
> main()? Is it necessary to use a main() when the script uses command line
> arguments? (See script below)
>
> #!/usr/bin/python
>
> impo
I would agree with the previous post but also add that I've stopped
calling the main function "main()" and usually give it a more
descriptive name, such as "bake_cookies()" or whatever. I think that
that makes it clearer what it's doing when used as a library and the 'if
__name__ == '__main__'" a
On Wed, Dec 11, 2013 at 9:26 PM, Ben Finney wrote:
> except SystemExit, exc:
For new code, you'd of course want to write that as:
except SystemExit as exc:
which is compatible with Python 2.6, 2.7, and 3.x, while the other
syntax is 2.x only.
ChrisA
--
https://mail.python.org/mailman/
JL writes:
> Python scripts can run without a main(). What is the advantage to
> using a main()?
Modular code – that is, implementing the program functionality in small,
well-defined units with narrow, strictly-defined interfaces – is good
design.
Practical benefits include being able to easily
Python scripts can run without a main(). What is the advantage to using a
main()? Is it necessary to use a main() when the script uses command line
arguments? (See script below)
#!/usr/bin/python
import sys
def main():
# print command line arguments
for arg in sys.argv[1:]:
pri
On Fri, Jul 10, 2009 at 5:52 PM, Tim wrote:
>
> Hi,
> I learned that a Python script is written in this way:
> def main():
> ...
> if __name__ == "__main__":
> main()
>
> Today, when I read a script, I found it has a different way:
>
> def main():
> ...
>
> main()
>
> It can run as well. C
On 2009-07-10, Tim wrote:
[RE-ORDERED]
> It can run as well. Can someone explain why and the rules that Python
> scripts get run?
Everything gets run by default. The def syntax defines functions but does
not run them -- they are only run when they are called
> Today, when I read a script, I fou
Hi,
I learned that a Python script is written in this way:
def main():
...
if __name__ == "__main__":
main()
Today, when I read a script, I found it has a different way:
def main():
...
main()
It can run as well. Can someone explain why and the rules that Python scripts
get run?
13 matches
Mail list logo