I have a series of text files that appear to contain a list of unicode values. For example, one file will have the following:
[u'01', u'13', u'20', u'30', u'32', u'43']
I'm new to python, but this looks like a list of unicode strings. Ultimately I want to convert them to a list of int, but I'm assuming I have to convert them to a list of regular strings first. Is this a poor assumption?
I've tried converting to UTF8, but it isn't give me the result I'm expecting.
I was getting this data through json, which apparently likes to return everything in unicode. I ended up converting the data immediately after retrieving it using a suggestion I found here. This gave me fewer problems further down the line.
[u'01', u'13', u'20', u'30', u'32', u'43']
I'm new to python, but this looks like a list of unicode strings. Ultimately I want to convert them to a list of int, but I'm assuming I have to convert them to a list of regular strings first. Is this a poor assumption?
I've tried converting to UTF8, but it isn't give me the result I'm expecting.
with open(filename, 'r') as txtFile: content = txtFile.readline() [x.encode('UTF8') for x in content] int_list = map(int, content)This code throws the following error:
Error:invalid literal for int() with base 10: '['
Can someone help me understand why, and what the correct way to go about this is?I was getting this data through json, which apparently likes to return everything in unicode. I ended up converting the data immediately after retrieving it using a suggestion I found here. This gave me fewer problems further down the line.