Re: How convert string '1e7' to an integer?

2009-11-08 Thread Roel Schroeven
Gary Herron schreef: Mensanator wrote: On Nov 7, 7:17 pm, Peng Yu pengyu...@gmail.com wrote: It seems that int() does not convert '1e7'. Because 'e' isn't a valid character in base 10. But 1e7 is a valid float, so this works: int(float('1e7')) 1000 That has a

Re: How convert string '1e7' to an integer?

2009-11-08 Thread Thomas
Just a curiosity, why does Python do this? l = [(base, int('1e7', base=base)) for base in range(15,37)] l [(15, 442), (16, 487), (17, 534), (18, 583), (19, 634), (20, 687), (21, 742), (22, 799), (23, 858), (24, 919), (25, 982), (26, 1047), (27, 1114), (28, 1183), (29, 1254), (30, 1327), (31,

Re: How convert string '1e7' to an integer?

2009-11-08 Thread Mick Krippendorf
Thomas wrote: Just a curiosity, why does Python do this? [(base, int('1e7', base=base)) for base in range(15,37)] [(15, 442), (16, 487), (17, 534), (18, 583), (19, 634), (20, 687), (21, 742), (22, 799), (23, 858), (24, 919), (25, 982), (26, 1047), (27, 1114), (28, 1183), (29, 1254), (30,

Re: How convert string '1e7' to an integer?

2009-11-07 Thread Mensanator
On Nov 7, 7:17 pm, Peng Yu pengyu...@gmail.com wrote: It seems that int() does not convert '1e7'. Because 'e' isn't a valid character in base 10. I'm wondering what function to use to convert '1e7' to an integer? int('1e7') int(1e7) 1000 Traceback (most recent call last):   File

Re: How convert string '1e7' to an integer?

2009-11-07 Thread Mick Krippendorf
Peng Yu wrote: It seems that int() does not convert '1e7'. It seems it does, though: int('1e7', base=16) 487 Mick. -- http://mail.python.org/mailman/listinfo/python-list

Re: How convert string '1e7' to an integer?

2009-11-07 Thread MRAB
Peng Yu wrote: It seems that int() does not convert '1e7'. I'm wondering what function to use to convert '1e7' to an integer? int('1e7') Traceback (most recent call last): File stdin, line 1, in module ValueError: invalid literal for int() with base 10: '1e7' In Python the e-form

Re: How convert string '1e7' to an integer?

2009-11-07 Thread Ben Finney
Mick Krippendorf mad.m...@gmx.de writes: Peng Yu wrote: It seems that int() does not convert '1e7'. It seems it does, though: int('1e7', base=16) 487 Well played, sir. -- \ “It is wrong to think that the task of physics is to find out | `\ how nature *is*. Physics

Re: How convert string '1e7' to an integer?

2009-11-07 Thread Gary Herron
Mensanator wrote: On Nov 7, 7:17 pm, Peng Yu pengyu...@gmail.com wrote: It seems that int() does not convert '1e7'. Because 'e' isn't a valid character in base 10. But 1e7 is a valid float, so this works: int(float('1e7')) 1000 That has a problem though, if you surpass the

Re: How convert string '1e7' to an integer?

2009-11-07 Thread Benjamin Kaplan
On Sat, Nov 7, 2009 at 8:17 PM, Peng Yu pengyu...@gmail.com wrote: It seems that int() does not convert '1e7'. I'm wondering what function to use to convert '1e7' to an integer? int('1e7') Traceback (most recent call last):  File stdin, line 1, in module ValueError: invalid literal for

Re: How convert string '1e7' to an integer?

2009-11-07 Thread Christian Heimes
Peng Yu wrote: It seems that int() does not convert '1e7'. I'm wondering what function to use to convert '1e7' to an integer? 1e7 is a way to express a float in science and math. Try float(1e7) Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: How convert string '1e7' to an integer?

2009-11-07 Thread Tim Chase
Mick Krippendorf wrote: Peng Yu wrote: It seems that int() does not convert '1e7'. It seems it does, though: int('1e7', base=16) 487 Bah...so narrow-minded ;-) print '\n'.join(Base %i: %i % (base, int('1e7', base=base)) for base in range(15,37)) Base 15: 442 Base 16: 487 Base 17: 534