arguments from the prompt
Thomas A. Bryan
tbryan at python.net
Mon Feb 7 18:33:51 EST 2000
joe at localhost.localdomain wrote:
> it says NameError: sys
> #!/usr/bin/python
> from sys import argv
>
> a=sys.argv[1]
When you use 'from sys import argv', the symbol 'argv' is now
available to your code directly. You no longer have to reference
the module name. In fact, sys is *not* available after you run
'from sys import argv' just like it isn't available after you run
'from sys import *'. If you simply write 'import sys', then the
symbol 'sys' is avialable, but 'argv' is only accessible through sys.
So, either write
from sys import argv
a = argv[1]
or
import sys
a = sys.argv[1]
---Tom
More information about the Python-list
mailing list