-5

I am using notepad++ and run my python programs in the python shell . I am working on unpacking the variables but when I call the program e.g in python shell import ex7.py it asks me to use more then 1 value to unpack

When I use import ex7.py first sec third it raises an invalid syntax exception.

Here is the program, I'm not just getting an idea of what to do with this:

from sys import argv

script, first, second, third = argv

print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • `argv` is set from the **command line** (`python ex7.py first sec third`), not with an import statement. Try unpacking a different sequence.. – Martijn Pieters Dec 30 '14 at 10:16
  • From the [`sys.argv` documentation](https://docs.python.org/2/library/sys.html#sys.argv): *The list of command line arguments passed to a Python script.* – Martijn Pieters Dec 30 '14 at 10:18

2 Answers2

2

To execute python code you should use "python file-name.py" but you used "import ex7.py" it's wrong

Please use : python ex7.py first sec third

Then output is:

ubuntu01:~$ python ex7.py first sec third

The script is called: ab.py

Your first variable is: first

Your second variable is: sec

Your third variable is: third

Sheshananda Naidu
  • 905
  • 1
  • 9
  • 10
0

To execute in python-shell place code inside the module in ex7.py file like:

import os

def abc(*arg):

  script, first, second, third = arg

  print "The script is called:", script

  print "Your first variable is:", first

  print "Your second variable is:", second

  print "Your third variable is:", third

In python-shell

>>> from ex7 import abc

>>> abc(parm1,parm2,parm3)
Sheshananda Naidu
  • 905
  • 1
  • 9
  • 10