Problem

Gordon McMillan gmcm at hypernet.com
Wed May 19 16:33:53 EDT 1999


William Tanksley wrote:

> On Wed, 19 May 1999 20:49:23 +0200, Frank de Bot wrote:
> >The strings are extracted from a file. (forgot to tell). Do you maybe know a way
> >to make the string valid to calculate with?
> 
> Sure.  If you know they're integers, you can use int(), like this:
> 
> str = "1023"
> x = int(str)
> 
> str = "9123478237486432678342688476234847262348764238L"
> y = long(str)
> 
William! Shame on you! You're creating the impression that there's 
only one way to do it. I feel it was incumbent upon you to imbue a 
sense of history by introducing string.atoi and friends. And I'm 
afraid that our functional friends will be very upset that you didn't 
use the obvious idiom:

reduce(lambda r, n:r*10+n, map(lambda c: ord(c)-ord('0'), str), 0)

no-honestly-I-really-love-my-real-job-<barf>-ly y'rs

- Gordon




More information about the Python-list mailing list