Strings for a newbie
Wolfram Kraus
kraus at hagen-partner.de
Fri May 27 09:20:23 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'
>
What is l[x]? Are you sure that l[x] is a string? Do a print before the
split to see what l[x] is. Oh, and no need for range here, if l is a list:
for x in l:
print x
h = x.split()
HTH,
Wolfram
More information about the Python-list
mailing list