I would like to use a txt file with configure variable for my python code.And I saw and copied following code from web to my python.
def getVarFromFile(filename):
import imp
f = open(filename)
global cs
cs = imp.load_source('cs', '', f)
f.close()
The strange thing is whenever I run the python code, I got a file named "c" in my directory, and it stores lots of strange characters like:
mò ;€-Rc
Why there comes this "c" file ? How can I get rid of that ? Thanks
----adding info----- I made the call by
getVarFromFile('config/cs.txt')
And my cs.txt looks like:
var1 = 'abc'
var2 = 'h'
var3 = '2'
var4 = '1'
And I use the data like:
var2 = int(cs.var2)
And by my debugging, once I put the
sys.exit()
Before
cs = imp.load_source('cs', '', f)
There is no such c file is generated. While I put exit after that line, there is the file named "c" generated.
So it must relate to that function