[Newbie]Trouble with string method
sean_berry at cox.net
Thu Mar 25 22:02:52 CET 2004
In order to do what you are trying here...
you would have to do something like the following.
L2 = 
for item in L:
then do your sort
This way, you are applying the lower to a string, and not the list.
If you do not need to change the case of all characters to lower, then
you should use my suggestion from my previous post.
If you do need to lower case all characters... then try what I have above.
calpolynate <nathanjohns77 at hotmail.com> wrote in message
news:96fd272b.0403251442.49047ba9 at posting.google.com...
> I'm attempting to open a file, read the lines, sort them, change any
> uppercase character to lowercase, and output to another file:
> import string
> unsorted = open('unsorted', 'r')
> L = unsorted.readlines()
> L = L.lower()
> sorted = open('sorted', 'w')
> when trying to run, I get this traceback:
> Traceback (most recent call last):
> File "sort_list.py", line 6, in ?
> L = L.lower(L)
> AttributeError: 'list' object has no attribute 'lower'
> Do I need to somehow convert the list into strings?
> Thanks for any help!
More information about the Python-list