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?
data = ((u'863579XK9',),)
print data[0][0] # prints "863579XK9"
>>> print ((u'863579XK9',),)[0][0]
863579XK9
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.