The u
at the front is just a visual item to show you, when you print the string, what the underlying representation is. It's like the single-quotes around the strings when you print that list--they are there to show you something about the object being printed (specifically, that it's a string), but they aren't actually a part of the object.
In the case of the u
, it's saying it's a unicode object. When you use the string internally, that u
on the outside doesn't exist, just like the single-quotes. Try opening a file and writing the strings there, and you'll see that the u
and the single-quotes don't show up, because they're not actually part of the underlying string objects.
with open(r'C:\test\foo.bar', 'w') as f:
for item in fname:
f.write(item)
f.write('\n')
If you really need to print strings without the u
at the start, you can convert them to ASCII with u'unicode stuff'.encode('ascii')
, but honestly I doubt this is something that actually matters for what you're doing.
You could also just use Python 3, where Unicode is the default and the u
isn't normally printed.