Flag control variable

Gary Herron gary.herron at islandtraining.com
Tue Feb 11 14:09:22 EST 2014


On 02/11/2014 10:59 AM, luke.geelen at gmail.com wrote:
>
>
> Look at the error message.  Carefully!  It says, quite clearly, the call
>
> to int is being passed a string "Adafruit-Raspberry-Pi-Python-Code",
>
> which of course can't be converted to an integer.
>
>
>
> Now the question is how you ran the program in such a manner that
>
> sys.argv[3] has such an odd value.
>
> What does your command line look like?  You didn't tell us, but that's
>
> where the trouble is.
>
>
>
> Gary Herron
> how do you meen "what does your command line look like?"

When you run this python script,  *how* do you do so?

Perhaps you type something like:
   python script.py 21 '*' 42
If not, then how do you supply values for the script's sys.argv?

If it is like that, then I see the most likely potential problem. The 
asterisk character (on Linux at least) is considered a wild-card 
character -- it is replaced by a list of local files so your command becomes
   python script.py 21 somefile1 somefile2 somefile3 <...and so on.> 42

If you put it in quotes, then it won't be expanded  (at least in the 
usual Linux shells -- you system may vary) and you'll end up with the 
asterisk in sys.argv[2] and the number in sys.argv[3].

Gary Herron




More information about the Python-list mailing list