Q: Passing an object of class UserList to writelines()

MikeK mkent at atlantic.net
Fri May 18 11:14:14 EDT 2001


I created a class derived from UserList to let me easily read a file into
a list, and write the list back to the file.

I want one of my 'FileListClass' objects to work just like a list, and be
treated just like a list.  However, when I try to pass one of my
'FileListClass' objects to the 'writelines' method of an 'os.popen' class
object, I get the following error:

TypeError: writelines() requires list of strings

This tells me that when I pass my 'FileListClass' object to 'writelines',
'writelines' is seeing the object, not the data part of the object.

I'm doing something wrong, possibly in the definition of my 'FileListClass'.
Any ideas?  I'm fairly new to Python, and readily admit that I don't have a
firm grasp on writing a Python class.



More information about the Python-list mailing list