First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
1

Read from Excel into Python

asked Dec 14 '12

Mongo gravatar image

updated Dec 14 '12

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 !

2 answers

Sort by » oldest newest most voted
1

answered Dec 18 '12

rimux gravatar image

try to use function str, e.g.

print str(u'R3')

gives for me result 'R3'

link
0

answered Dec 15 '12

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
link

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 (Dec 24 '12)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

Stats

Asked: Dec 14 '12

Seen: 893 times

Last updated: Dec 18 '12