Strange (for a newbie) problem

Josiah Carlson jcarlson at nospam.uci.edu
Sat Feb 21 13:30:48 EST 2004


> I'm experiencing the following problem. 
> I have a python script analyses.py where a certain point I have to
> define a variable called 'code' like:
> 
> code=151
> 
> The program works fine but if I change that line in 'code=sys.argv[1]'
> using the sys module in order to give to the program that code as a
> parameter (i.e. I then run this script as "python analyses.py 151" from
> the shell) then the program returns an error complaining that a certain
> variable different from code is not defined.
> 
> What is my mistake?

Depending on where 'code = sys.argv[1]' is placed, this could be your 
problem.

Another thing to note is that everything in sys.argv is a string.  Try 
using the following:

code = 151
if len(sys.argv) > 1:
     try:
         code = int(sys.argv[1])
     except:
         pass


  - Josiah





More information about the Python-list mailing list