I have a python script 'main.py' which calls another python script called 'getconf.py' that reads from a file 'configuration.txt'. This is what it looks like:
if __name__ == "__main__":
execfile("forprolog.py") # this creates configuration.txt
execfile("getconf.py")
When getconf.py is called via main.py
it sees configuration.txt
as an empty file and fails to read the string from it.
This is how I read from a file:
f1 = open("configuration.txt")
conf = f1.read() #this string appears to be empty
print f1
returns <open file 'D:\\DIPLOMA\\PLANNER\\Exe\\configuration.txt', mode 'r' at 0x01A080D0>
print f1.read()
returns an empty string
I suspect the reason of the failure is that the file is being written immediately before calling getconf.py
. If I run main.py
when configuration.txt
is already there it works. Adding a time delay between the actions doesn't solve the problem.
Would appreciate any help!