newbe how to read in a string?
Steffen Ries
steffen.ries at sympatico.ca
Sat Mar 24 09:38:59 EST 2001
"Alex Martelli" <aleaxit at yahoo.com> writes:
> "Chris Gonnerman" <chris.gonnerman at usa.net> wrote in message
> news:mailman.985355670.6600.python-list at python.org...
> [snip]
> > import string
> > seq = string.split(a, ",")
> > for i in range(1, len(seq)): # this skips the 0 index,
> > seq[i] = float(seq) # which needs to stay a string.
> >
> > In Python 2.0 the code might be shorter, using string methods and list
> > comprehension, but I personally prefer the "old way" myself.
>
> The 'old way' would be
> seq = map(float, string.split(a, ','))
> and it still works fine of course, though I'd rather spell it
> seq = map(float, ','.split(a))
You're (ab)using ",".join(seq) too much, it seems :-)
What you wanted to say is: "seq = map(float, a.split(','))" (not
counting the conversion problem of the first element...)
/steffen
--
steffen.ries at sympatico.ca <> Gravity is a myth -- the Earth sucks!
More information about the Python-list
mailing list