Python help
Antaeus Feldspar
feldspar at ix.netcom.com
Sat May 25 09:19:52 EDT 2002
If you are working with an older interpreter, you will need to add the line
import string
to your code, preferably just below "#!/usr/bin/python". This will
import the 'string' module, which contains most of the string
manipulation routines, and then to use these routines, you call
"string.split(mystring,"|") or something similar.
In later versions of python, the string manipulation routines were added
directly to the string datatype.
Occean wrote:
> 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