-2

I have a function that takes in and reads a csv file such that when i can type

python myscript.py filename.csv to run my script. Below is my function :

def read(sys.argv[1]):
 ...
 ...

However i get this error:

  File "myscript.py", line 6
    def read(sys.argv[1]):
                ^
SyntaxError: invalid syntax

How can i re write my script to be able to do this?

Thanks,

jxn
  • 7,685
  • 28
  • 90
  • 172

1 Answers1

7

You need to pass sys.argv[1] as an argument to read when you call it, not when you define it:

def read(argument): # define it with argument
    print argument  # do whatever with "argument"

read(sys.argv[1])   # call it here
mhlester
  • 22,781
  • 10
  • 52
  • 75