How do I cast data readed from arduino w/ python?

Hi I've been interfacing arduino using python and pyserial as shown on other topics of this forum.

I'm trying to use numerical data readed from an arduino Duemilanove board, but I can only read text from it. When I try to cast the readed string, python fails telling me the string is unabled to be parsed as float. I've noticed the data string I get has some kind of extra format chars on it, non printable using the "print" statement.

Does anybody knows how can I read numerical data from my Duemilanove Arduino using python.

Please help! :)

Does the string have a 'trim' method? That removes the most common 'whitespace' characters (space, breakline, newline feed, tab, sometimes a couple of others aswell such as vertical tab)

The safest way IMO is to use write/readln at both ends and use ASCII. So at the Arduino side


At the Python side

numString = Serial.readln()

You can then convert the thing to any number type you need (int. float, etc)