Python help
Jere Kahanpaa
kahanpaa at gstar.astro.helsinki.fi
Sat May 25 07:31:25 EDT 2002
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
--
It's hard to think outside the box when you ARE the box.
- unknown, alt.religion.kibology
More information about the Python-list
mailing list