Python help

Occean tritran2001 at iprimus.com.au
Sat May 25 09:58:58 EDT 2002


I tried to use it but i get some error 

#!/usr/bin/python 
def splitpart(x):
    return x.split(':')[1]
 
 s = "Student name:Yajen | Class:143 | ID:205851C"
 stName, stClass, stId = map(splitpart,s.split('|'))

print stName
print StClass
print stId   

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'

In article <acnsmd$5d8$1 at oravannahka.helsinki.fi>, "Jere Kahanpaa"
<kahanpaa at gstar.astro.helsinki.fi> wrote:

> tritran <tritran2001 at iprimus.com.au> wrote:
>> Assume that i got the string of text such as "Student name:Yajen |
>> Class: 143 | ID:205851C"
>> I like to seperate this line into the 3 varibles like stName, stClass,
>> and stId. How can i do this, can someone help me. Thank a lot
> 
> Simple solution (withot any error checking!):
> 
> 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,'|')
> 
> Jere



More information about the Python-list mailing list