0
if __name__ == "__main__":
    file = sys.argv[1]
    f = FST("q0")
    #f.addState("1", True)
    #f.addState("2", True)
    #f.addState("3", True)

in line file = sys.argv[1] getting this error. can anyone please help me out.

vaultah
  • 44,105
  • 12
  • 114
  • 143

2 Answers2

1

The sys.argv list is populated only when command line arguments to the script are present. sys.argv[0] is the name of the script you are running. sys.argv[1] will be the first command line argument passed to the script. You need to call your script like:

python SCRIPT_NAME FIRST_ARG
Matt Davidson
  • 728
  • 4
  • 9
0

You're probably running your script without arguments while it expects at least one.

sys.argv is the list of arguments given to the script. sys.argv[0] is the script itself; sys.argv[1] is the first actual argument. If you give no argument to the script, 1 is an out of range index.

Arkanosis
  • 2,229
  • 1
  • 12
  • 18