0

Using VScode + code runner extension

Once input() function receives a string like "qwe", program returns "NameError: name "qwe" is not defined" If input receives a string of numbers like "123", everything goes well. All files exist in right directory,and named/formatted pretty fine. Example of function:

def maker():
    fileVar = str(input())
    fileVar = lineFixer(fileVar)
    with open(fileVar+".csv","r") as workfile:
        for line in workfile:
            return(line)

lineFixer is a dumb function for some cases (has no influence on result):

def lineFixer(line):
    line = line.strip('\n')
    line = line.strip('\t')
    line = line.replace('\n','')
    line = line.replace('\t','')
    return line

Without str(input()), it's rubbish.

martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

1

The trouble that you are having is because you are using input() rather than raw_input().

Modify your code to read fileVar = raw_input()

The difference between these two is that input is trying to evaluate your input as code. That's why you get the error with XYZ not being defined, it thinks it is a variable. Also, with using raw_input, you no longer should need the casting into a string with str().

EDIT: I am assuming, since you have not specified this and from the error you are getting, that you are using Python2.X. In Python3, there should be only input(), working as raw_input().

Alexander Rossa
  • 1,900
  • 1
  • 22
  • 37