I know this is basic but it has been nagging me for a while now. I am new to Python coding so please have patience.
I am using a Python script to read from MySQL and relay this information to a .txt file using the first line of an existing text file as the name of the new one. All of the MySQL stuff is working fine but I have a problem writing to the .txt file. Code is below:
import MySQLdb
text_file = open("configure.txt","r")
testCamp = (text_file.readline())
print testCamp
text_file.close()
db = MySQLdb.connect(host='localhost',user='username',passwd='password')
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
disp = cursor.fetchone()
print "Database Version: %s " %disp
db.close()
text_file = open(testCamp, "w")
text_file.write("Some Text\n")
input("\n\nPress Enter to Exit.")
As you can see from the code above I am in the process of setting up the framework so I'm not getting any data from the database yet. The new testCamp file is created ok (although it does not display the .txt extension instead it has some unfamiliar box icon after it). I have checked the file type and it does say it is a normal text file and I have also checked that the permissions allow writing and they do. Interestingly I also tried writing to a text file that was already in place:
text_file = open("Test.txt","w")
text_file.write("Some Text\n")
and it still did not work! Any suggestions would be appreciated