Simple Object assignment giving me errors

Dave Angel davea at
Wed Feb 12 22:41:29 CET 2014

 Nir <nirchernia at> Wrote in message:
> This is from the book 'dive into python'. I am trying to define jeez as being an instance of FileInfo.
> class UserDict(object):
> 	def __init__(self, dict = None):
> = {}
> 		if dict is not None: self.update(dict)
> class FileInfo(UserDict):
> 	def __init__(self, filename=None):
> 		UserDict.__init__(self)
> 		self["name"] = filename
> jeez = FileInfo("yo")
> I get a TypeError: 'FileInfo' object doesn't support item assignment .
> Am I missing something?

Yes, you're missing the rest of the error message.  Show the
 whole thing, including the stack trace,  and I'm sure it'll be
 clear that the error happened long before jeez was involved.

I figure that the line in error is 
		self["name"] = filename

and that what you really need is ["name"] = filename

You also have a similar problem on the last line of the first class.


More information about the Python-list mailing list