Python help

Peter Hansen peter at engcorp.com
Sat May 25 10:26:21 EDT 2002


"Occean", please don't top-post.  Put your response below the original:

Occean wrote:
> 
> <kahanpaa at gstar.astro.helsinki.fi> wrote:
> > def splitpart(x):
> >    return x.split(':')[1]
> >
> > s = "Student name:Yajen | Class:143 | ID:205851C" stName, stClass, stId
> > = map(splitpart,s.split('|'))
> >
> > # Note: Older version require string.split(s,'|')
>
> I tried to use it but i get some error
> 
> Errors involked : Traceback (innermost last):
>                                 File "./splitPark.py",line 9 ,in?
>                            stName, stClass, stId = map(splitpart,s.split('|'))
> AttributeError:'string' object has no attribute 'split'

Are you using Python 1.5.2?  Note Jere's warning that some older
versions may require "string.split()".  Try this instead:

import string
def splitpart(x):
    return string.split(x, ':')[1]

and ..... map(splitpart, string.split(s, '|')) ...

-Peter



More information about the Python-list mailing list