[Newbie]Trouble with string method

calpolynate nathanjohns77 at hotmail.com
Thu Mar 25 17:42:04 EST 2004


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.sort()
L = L.lower()
sorted = open('sorted', 'w')
sorted.writelines(L)
unsorted.close()
sorted.close()

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 mailing list