I am self-taught in MySQL, Python and Linux based OS, and quite sure there must be a more elegant solution to the problem, or, at least, one that works along my lines. The code is taking data from the last 24 hours from a database and storing them to a .txt file to be handled further on. However, the output I am getting has additional symbols that are making further analysis troublesome - I want to know if there is a way to remove them.
My (relevant) code is:
...
cur = db.cursor()
cur.execute("SELECT * FROM Sens WHERE sdate > DATE_SUB(NOW(),INTERVAL 24 HOUR)")
query = cur.fetchall()
OutputFile = open("/root/Desktop/data.txt", "w")
for i in range (0, len(query)):
print>>OutputFile, query[i]
...
The reason I am using for loop is to have each row fetched printed in a newline. The result I get is as follows:
('0,01/24/16,12:41:49,45.185\r\r\n',)
The result I need is:
0,01/24/16,12:41:49,45.185
Much appreciate the help, LZ.
query[i][0]and if there are still some chars left you can usereto help.