I am willing to save the file with the same name as the variable has. See teh following code:
training = np.arange(200)
np.savetxt(training.txt,training)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'txt'
When I use double quotes it will work as obvious:
np.savetxt("training.txt",training)
But in my program there are different variables and I want that when I call the file saving function the file name should automatically be taken as the variable name itself.
For example, if the variable is question
, or answer
, then when I say save()
, the file name should automatically be question.txt
or answer.txt
Suggest me what I can do to achieve this.