Ex13 - import args


#1

Hi,
I did some modification on ex13.py, the same I did when I was studying the python2 book.
I ran the code below without any arguments after the call (python3 ex13.py) and this
won’t work as it did in (python ex13.py) call.
In python 3 the code runs but none arg is printed. Why?

Appreciate any help.

Python 2.7: (It works)

from sys import argv
script = argv[0]

first = argv = raw_input("> “)
second = argv = raw_input(”> “)
third = argv = raw_input(”> ")

print “The script is called:”, script
print “Your first variable is:”, first
print “Your second variable is:”, second
print “Your third variable is:”, third

Python 3.7: (it runs but wont print args I entered in input fields)

from sys import argv
script = argv[0]

first = argv = input("> “)
second = argv = input(”> “)
third = argv = input(”> ")

print (“The script is called:”), script
print (“Your first variable is:”), first
print (“Your second variable is:”), second
print (“Your third variable is:”), third


#2

Do: script, first, second, third = argv
You don’t need both input() and argv.


#3

Hey @thom I believe I replied on email, but the short version of what I sent you is:

Stop trying to do both 2 and 3 at the same time. Basically forget about 2, just do 3, and then keep going so you learn more. Also, this line:

second = argv = raw_input(”> “)

Should never have worked. Adding the argv in the middle makes no sense really, so Python 3 is probably doing the right thing there. Rewrite those as:

second = raw_input(”> “)

#4

Yes. I did the way you told me and it was ok.

from sys import argv

script = argv[0]

first = input("> “)
second = input(”> “)
third = input(”> ")

print (“The script is called:” , script)
print (“Your first variable is:” , first)
print (“Your second variable is:” , second)
print (“Your third variable is:” , third)

This way I do not need to enter the args during the “python3 ex13.py”
I enter the args on the inputs prompt.