Convert '165.0' to int

Chris Angelico rosuav at gmail.com
Sat Jul 23 11:20:35 EDT 2011


On Sun, Jul 24, 2011 at 1:12 AM, Billy Mays <noway at nohow.com> wrote:
> On 7/23/2011 3:42 AM, Chris Angelico wrote:
>>
>> int(s.rstrip('0').rstrip('.'))
>>
>
> Also, it will (in?)correct parse strings such as:
>
> '165............00000000000000'
>
> to 165.

Yes, it will, but is that an issue to the OP? Programming is about
solving the problem you have, not the problems you don't have.
Sometimes it's better to have a simple solution that does the job than
an extremely complex one that isn't excessively lenient. Is it such a
problem for it to be lenient?

ChrisA



More information about the Python-list mailing list