Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66097
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re:Simple Object assignment giving me errors |
| Date | 2014-02-12 16:41 -0500 |
| Organization | news.gmane.org |
| References | <d7d2865e-4184-4c05-b1bd-b4f16547b2f2@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6794.1392241090.18130.python-list@python.org> (permalink) |
Nir <nirchernia@gmail.com> 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):
> self.data = {}
> 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
self.data ["name"] = filename
You also have a similar problem on the last line of the first class.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Simple Object assignment giving me errors Nir <nirchernia@gmail.com> - 2014-02-12 13:18 -0800
Re: Simple Object assignment giving me errors Chris Angelico <rosuav@gmail.com> - 2014-02-13 08:26 +1100
Re:Simple Object assignment giving me errors Dave Angel <davea@davea.name> - 2014-02-12 16:41 -0500
Re: Simple Object assignment giving me errors Nir <nirchernia@gmail.com> - 2014-02-12 13:42 -0800
Re: Simple Object assignment giving me errors Chris Angelico <rosuav@gmail.com> - 2014-02-13 08:48 +1100
Re: Simple Object assignment giving me errors Jerry Hill <malaclypse2@gmail.com> - 2014-02-12 17:09 -0500
Re: Simple Object assignment giving me errors Nir <nirchernia@gmail.com> - 2014-02-12 14:25 -0800
csiph-web