Strange (for a newbie) problem

A

Angelo Secchi

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?
Thanks
angelo
 
J

Josiah Carlson

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
 
A

Alan Gauld

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?

Dunno. You need to give us more information. Without seeing where
the error occurs, how the other variable is both defined and
used, we cannot guess what you might be doing! Well, we could
guess but its not likely to be very profitable!

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
 
W

wes weston

Angelo,
Yes, more info is needed. One thing that could move
your error to a latter line and confuse you is that you
can "multiply" strings.
<type 'str'>

wes

Angelo said:
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?
Thanks
angelo
 
A

Angelo Secchi

Thanks Alan, Peter, Wes and Josiah.
Noting that sys.argv[1] was a string solved the problem!!!
Sorry...
angelo






Angelo,
Yes, more info is needed. One thing that could move
your error to a latter line and confuse you is that you
can "multiply" strings.
<type 'str'>

wes

Angelo said:
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?
Thanks
angelo


--
========================================================
Angelo Secchi PGP Key ID:EA280337
========================================================
Current Position:
Graduate Fellow Scuola Superiore S.Anna
Piazza Martiri della Liberta' 33, Pisa, 56127 Italy
ph.: +39 050 883365
email: (e-mail address removed) www.sssup.it/~secchi/
========================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,968
Members
47,518
Latest member
TobiasAxf

Latest Threads

Top