In Python I pull in data via Win32Com as a tuple:
((u'863579XK9',),)
How can I parse this so that I am left with just 863579XK9 so I can write that to a file?
asked Sep 13, 2011 at 20:10
Captain Cretaceous
8213 gold badges8 silver badges14 bronze badges
3 Answers 3
data = ((u'863579XK9',),)
print data[0][0] # prints "863579XK9"
Sign up to request clarification or add additional context in comments.
Comments
>>> print ((u'863579XK9',),)[0][0]
863579XK9
answered Sep 13, 2011 at 20:13
Wooble
90.6k12 gold badges111 silver badges132 bronze badges
Comments
Since this is a unicode string, you'd want to write it to a unicode encoded file:
import codecs
myfile = codecs.open('myfile.txt', encoding='utf8', mode='w')
data = ((u'863579XK9',),)
myfile.write(data[0][0].encode('utf8'))
myfile.close()
See Reading and Writing Unicode Data from the Python Unicode HOWTO.
answered Sep 13, 2011 at 20:20
Alex Smith
1,53512 silver badges13 bronze badges
Comments
lang-py