[Python-es] invalid literal for int() with base 10

Diego Uribe Gamez diego.uribe.gamez en gmail.com
Sab Dic 17 18:08:00 CET 2011


Resulta que el problema que tengo es un poco complejo y es que la Lista que
tengo contiene Strings pero en realidad son números.

Intente la función normal de python para convertir todos los Strings en
Enteros:

for i in range(len(self.Cadenastring)):
    self.Cadenapura = int(self.Cadenastring[i])

Cadenastring = ['2', '012642000444971' , '151938.00' , '0440.132117',
'0.0', '0.0', '171211', '5.5', ]

*Error:*
self.Cadenapura = int(self.Cadenastring[i])
ValueError: invalid literal for int() with base 10: ''

*Encontré esta información:*

http://docs.python.org/library/string.html

Convert string *s* to an integer in the given *base*. The string must
consist of one or more digits, optionally preceded by a sign (+ or -). The *
base* defaults to 10. If it is 0, a default base is chosen depending on the
leading characters of the string (after stripping the sign): 0x or 0X means
16, 0 means 8, anything else means 10. If *base* is 16, a leading 0x or 0X is
always accepted, though not required. This behaves identically to the
built-in function int()
<http://docs.python.org/library/functions.html#int> when
passed a string. (Also note: for a more flexible interpretation of numeric
literals, use the built-in function
eval()<http://docs.python.org/library/functions.html#eval>
.)
*El problema:*
No se trata de una Lista de números matemáticos, es solo un texto en
con números escritos que debo cambiarles el Type pero no logro hacerlo?

-- 
 *Diego Alonso Uribe Gamez*
------------------------------

*Desarrollador web*

Twitter: @DiegoUG <http://www.twitter.com/DiegoUG>

Google+: http://gplus.to/diegoug
------------------------------
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20111217/d15e35a9/attachment.html>


Más información sobre la lista de distribución Python-es