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?

asked Sep 13, 2011 at 20:10
0

3 Answers 3

3
data = ((u'863579XK9',),)
print data[0][0] # prints "863579XK9"
answered Sep 13, 2011 at 20:12
Sign up to request clarification or add additional context in comments.

Comments

1
>>> print ((u'863579XK9',),)[0][0]
863579XK9
answered Sep 13, 2011 at 20:13

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.

answered Sep 13, 2011 at 20:20

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.