Ask Your Question
1

Read from Excel into Python

asked 2012-12-14 13:56:39 -0600

Mongo gravatar image

updated 2012-12-14 14:54:08 -0600

Hi friends,

I am trying to set up Python to read the "Branch ID" that I have typed into an Excel sheet. Let's say that my branch ID is R3, and I have simply typed R3 as it is in the Excel cell, without quotes or whatever.

Python reads it like [u'R3'].

I am using excelpy (book.get_range), not xlrd, but I remember having had this problem before with XLRD too.

I want Python to read it like ["R3"], I mean, I want it to read it as a string.

Please, does anyone know how to get rid of the u character ?

Thanks,

Andre

P.S. I think I got the answer myself, I have converted the entire array to string and the u disappeared, thanks !

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2012-12-18 02:09:34 -0600

rimux gravatar image

try to use function str, e.g.

print str(u'R3')

gives for me result 'R3'

edit flag offensive delete link more
0

answered 2012-12-15 17:31:29 -0600

JervisW gravatar image

That u character means that Python is treating the string as unicode.

The Python website has an article explaining its support of unicode though its very long!

In practice, I'm not sure if PSSE accepts unicode strings. For instance could you name a bus like this:

✎၉ꩦꩬ

Probably not right? Even one with umlaut:

nuclëar

might cause a problem. But I've made a note to test this and come back and let you know for sure! If it turns out that PSSE cannot accept those characters here's a way to convert while stripping out any non-ascii ones:

>>> print u'nuclëar'.encode('ascii', 'ignore')
nuclar
edit flag offensive delete link more

Comments

Hi friends, Thanks for helping ! I'll test these solutions as soon as I am back at work on Jan 8th; Merry X-mas and happy 2013 ! Andre

Mongo gravatar imageMongo ( 2012-12-23 23:12:18 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

Stats

Asked: 2012-12-14 13:56:39 -0600

Seen: 887 times

Last updated: Dec 18 '12