Search code examples
pythonreadfile

Python readlines() returns empty string


I ran the following code in Python:

def translateDesc(fileName):
    textFile = open("fileName", "r")
    fileLines = textFile.readlines()
    return fileLines

And the function returns an empty string. However, when I ran the lines one by one in the iPython terminals, the function returned was not empty. How should I fix this issue?


Solution

  • please replace 2nd line with below: textFile = open(fileName, "r")

    #we need to use the variable name in line 2 instead of string "fileName".