Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66104
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <malaclypse2@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'class,': 0.07; 'great.': 0.07; 'filename': 0.09; 'lookup': 0.09; 'snippet': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'def': 0.12; '"from': 0.16; 'awesome.': 0.16; 'code?': 0.16; 'collections': 0.16; 'instead).': 0.16; 'subject:Object': 0.16; 'url:file': 0.16; 'userdict': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'library': 0.18; 'wed,': 0.18; 'trying': 0.19; 'feb': 0.22; 'example': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'question': 0.24; 'cc:2**0': 0.24; 'source': 0.25; 'handling': 0.26; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'class': 0.32; 'url:python': 0.33; 'guess': 0.33; 'sense': 0.34; 'skip:_ 10': 0.34; 'skip:u 20': 0.35; 'received:google.com': 0.35; 'subject:Simple': 0.36; 'responsible': 0.36; 'url:org': 0.36; 'should': 0.36; 'being': 0.38; 'minimum': 0.38; '(i.e.,': 0.38; 'handle': 0.38; 'pm,': 0.38; 'little': 0.38; 'does': 0.39; '12,': 0.39; 'how': 0.40; 'then,': 0.60; 'break': 0.61; 'mentioned': 0.61; 'url:3': 0.61; "you're": 0.61; 'first': 0.61; 'here:': 0.62; 'show': 0.63; 'name': 0.63; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'bare': 0.84; 'url:cpython': 0.84; 'thing,': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=MjSDau8BToH+ORgD76BYF3hBIGYueKyvj7OyKb7Se+0=; b=XaD3Op+hP7IAEEPqAEiexBgYu21uJsAuxcxLeFr96sGiseWmySxXq5gDDAiAarPp7f Flmo+t7gIPrVv18T+KjMgC0skJBVgcgg4q6va++y1VxxcdO9CZRtDgBPQUGWvAVi4jSw S+6tMdKtx3Z+P/+95eKhNS8dpM1pM0D1Yt+R1d+0PIEYbEplXXre2Rn89YTa2ffFWEr7 9FzBVTs/F5DNPjSEuN+B2uan7BENh8iv1IMgZlC+ZQQJb62xNjpeUF6iK5ur0hOp+S8M ByYYNDBJKKFQMVgamlfL4KIn1ZcmsvraGKA7yz6x8wS1hxuCqDv8x92ZLzwRGkWLKkoI VBbQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.66.16.131 with SMTP id g3mr25629114pad.138.1392242940256; Wed, 12 Feb 2014 14:09:00 -0800 (PST) |
| In-Reply-To | <5697d584-28ba-44e6-a60a-cb5ff9ae19aa@googlegroups.com> |
| References | <d7d2865e-4184-4c05-b1bd-b4f16547b2f2@googlegroups.com> <5697d584-28ba-44e6-a60a-cb5ff9ae19aa@googlegroups.com> |
| Date | Wed, 12 Feb 2014 17:09:00 -0500 |
| Subject | Re: Simple Object assignment giving me errors |
| From | Jerry Hill <malaclypse2@gmail.com> |
| To | Nir <nirchernia@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | "python-list \(General\)" <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6799.1392242945.18130.python-list@python.org> (permalink) |
| Lines | 33 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1392242945 news.xs4all.nl 2953 [2001:888:2000:d::a6]:55802 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:66104 |
Show key headers only | View raw
On Wed, Feb 12, 2014 at 4:42 PM, Nir <nirchernia@gmail.com> wrote:
> If this makes sense to you, great. I am trying to break it down so that I can make sense of it. As you mentioned self["name"] = filename doesn't work unless I built a class to handle it. I guess my question then, is how is the class handling it in this code? If you can show me by stripping it down to the bare minimum or write an example that would be awesome.
This example works because the UserDict object being used in this code
was built to handle it. The UserDict class in the standard library
does a lot more than the little snippet you had in your original code.
Your original code would work if you did the same thing, like this:
from collections import UserDict
class FileInfo(UserDict):
def __init__(self, filename=None):
UserDict.__init__(self)
self["name"] = filename
jeez = FileInfo("yo")
(If you're using Python 2, then the first line should be "from
UserDict import UserDict" instead).
You can take a look at the source code for the userDict class here:
http://hg.python.org/cpython/file/3.3/Lib/collections/__init__.py#l862
. In that class, the code responsible for handling the bracketed name
lookup (i.e., self["name"]), is in the __getitem__ and __setitem__
methods (and peripherally in __delitem__, __len__ and __contains__)
--
Jerry
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