Reputation: 11
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?
Upvotes: 0
Views: 1267
Reputation: 665
readlines()
returns a list of strings.If you want to return string use read()
def translateDesc(fileName):
textFile = open(fileName, "r")
fileLines = textFile.read()
return fileLines
Upvotes: 1
Reputation: 16
please replace 2nd line with below: textFile = open(fileName, "r")
#we need to use the variable name in line 2 instead of string "fileName".
Upvotes: 0