Strings for a newbie

John Machin sjmachin at lexicon.net
Fri May 27 09:12:17 EDT 2005


Malcolm Wooden wrote:
> my actual code is:
> 
>   for x in range(len(l)):
>     h = string.split(l[x])
> 
> where the sentence string is in an array of one element 'l'
> Error is:
> 
> Traceback (most recent call last):
>   File "<string>", line 34, in ?
>   File "<string>", line 27, in SentenceText
>   File "C:\PYTHON22\lib\string.py", line 122, in split
>     return s.split(sep, maxsplit)
> AttributeError: 'list' object has no attribute 'split'
> 
Can't tell from that -- do you have "import string" above that, or what?

Please post the whole file, which BTW you should not call "string".
In any case you should not be using the string module; it's old and 
deprecated. Use string methods instead. Why are you using Python 2.2??

I have to go now; it's way past bedtime at this longitude. Like I said, 
post the *whole* file; others will be able to straighten you out when 
they see the gory detail :-)

Cheers,
John



More information about the Python-list mailing list