I'm working on my python script to pull the data from the sqlite3 database.
I'm trying to convert the data so that the strings are no longer unicode and the dates but the dates are still showing the L
strings which you can see it here:
11:02:51 T:3016 NOTICE: ('101 ABC FAMILY ', 'The Goonies',
20140520173000L, 20140520200000L)
11:02:51 T:3016 NOTICE: ('101 ABC FAMILY ', 'Pirates of the Caribbean: On
Stranger Tides', 20140520200000L, 20140520230000L)
Used this code:
#Pull the data from the database
channelList = list()
channel_db =
xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide',
'source.db'))
if os.path.exists(channel_db):
con.text_factory = lambda x: x.encode('ascii')
cur.execute('SELECT channel, title, start_date, stop_date
FROM programs WHERE channel')
for row in cur:
channel = row[0], row[1], row[2], row[3]
channelList.append(channel)
print channel
cur.close()
And when I tried this:
for row in cur:
row[0].encode('ascii'), row[1].encode('ascii'), int(row[2]), int(row[3])
channelList.append(channel)
print channel
On the first code, it will removed the u
strings, but on both codes it will not remove the L
strings.
Can you please tell me how I can remove the L
strings and what type of function I should use?
The 'L' signifies long
built-in numeric type. You probably don't really need to get rid of it, but if you do, you can use constructors to convert between types:
>>> int(1L)
1
>>> long(1)
1L
You can also convert the timestamp to a datetime.datetime
object using strptime:
>>> datetime.datetime.strptime(str(20140520173000L), "%Y%m%d%H%M%S")
datetime.datetime(2014, 5, 20, 17, 30)