What does this statement do???
Ivan Van Laningham
ivanlan at callware.com
Tue May 25 17:10:23 EDT 1999
Hi All--
"Jr. King" wrote:
>
> #if sys.argv[1:]: n = int(sys.argv[1])
>
> Thanks
As it is written, nothing. It's a comment, as indicated by the # in
column 1.
If you remove the octothorpe (#) sign, it tests for the existence of
sys.argv[1], that is, it executes the part of the line after the : if
and only if there was an argument on the command line:
spam.py
will do nothing, but
spam.py 3114
will convert the "3114" argument string into an integer. That assumes
that the user types in nothing but numbers.
spam.py 311a
will make it barf. To make it more bulletproof, read up on exceptions.
<we-don't-need-no-stinkin'-ints>-ly y'rs,
Ivan
----------------------------------------------
Ivan Van Laningham
Callware Technologies, Inc.
ivanlan at callware.com
http://www.pauahtun.org
See also:
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps: Cu Chi, Class of '70
----------------------------------------------
More information about the Python-list
mailing list