Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'assignment': 0.07; 'none:': 0.07; 'filename': 0.09; 'none):': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'self.data': 0.09; 'def': 0.12; 'wrote': 0.14; 'dict': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Object': 0.16; 'typeerror:': 0.16; 'trying': 0.19; 'stack': 0.19; 'error': 0.23; 'class.': 0.26; 'define': 0.26; 'header:X-Complaints-To:1': 0.27; 'rest': 0.29; "doesn't": 0.30; "i'm": 0.30; 'class': 0.32; 'figure': 0.32; 'skip:_ 10': 0.34; 'message.': 0.35; 'problem': 0.35; 'skip:u 20': 0.35; 'really': 0.36; 'subject:Simple': 0.36; 'similar': 0.36; 'clear': 0.37; 'being': 0.38; 'to:addr:python- list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; "you're": 0.61; 'first': 0.61; 'show': 0.63; 'subject::': 0.85; 'involved.': 0.91; 'thing,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re:Simple Object assignment giving me errors Date: Wed, 12 Feb 2014 16:41:29 -0500 (EST) Organization: news.gmane.org References: X-Gmane-NNTP-Posting-Host: dpc6744192124.direcpc.com X-Newsreader: PiaoHong Usenet NewsReaders 1.36 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392241090 news.xs4all.nl 2939 [2001:888:2000:d::a6]:34015 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66097 Nir 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