1

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?

0

3 Answers 3

3
data = ((u'863579XK9',),)
print data[0][0] # prints "863579XK9"
Sign up to request clarification or add additional context in comments.

Comments

1
>>> print ((u'863579XK9',),)[0][0]
863579XK9

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.