Trying to simplify lots of repetitive reading and writing in a script of mine, and I can not figure out how to get data out of def readfile
.
def writefile(FILE, DATA):file = open(FILE, "w")X = str(DATA) file.write(X)file.close()def readfile(FILE):file = open(FILE, "r")readvar = file.read()file.close()readfile("BAL.txt")
print(readvar)
I would expect the value stored in BAL.txt
to come back, but it always says that readvar
is not defined. I just defined it in a function that I ran.
Error:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-6-f80fb5b2da05> in <module>14 15 readfile("test.txt")
---> 16 print(readvar)NameError: name 'readvar' is not defined