Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70528
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <sailor@lists.xtsubasa.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.072 |
| X-Spam-Evidence | '*H*': 0.86; '*S*': 0.00; 'attribute': 0.07; 'python': 0.11; "'__doc__',": 0.16; 'attributes.': 0.16; 'class:': 0.16; 'object()': 0.16; 'subject:object': 0.16; 'x()': 0.16; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'pass': 0.26; "skip:' 10": 0.31; '"",': 0.31; 'file': 0.32; 'class': 0.32; '(most': 0.33; 'objects': 0.35; 'there': 0.35; 'shorter': 0.36; 'list': 0.37; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'explain': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'new': 0.61; 'simple': 0.61; 'different': 0.65; 'subjectcharset:iso-8859-1': 0.66; "'foo'": 0.84; "'object'": 0.84 |
| X-PV-Sent | sailor@lists.xtsubasa.org |
| From | Pavel Volkov <sailor@lists.xtsubasa.org> |
| To | <python-list@python.org> |
| Subject | object().__dict__ |
| Date | Wed, 23 Apr 2014 09:39:04 +0400 |
| User-Agent | Trojita/0.4.1; Qt/4.8.5; X11; Linux; |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | quoted-printable |
| 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.9451.1398231951.18130.python-list@python.org> (permalink) |
| Lines | 35 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1398231951 news.xs4all.nl 2923 [2001:888:2000:d::a6]:56932 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:70528 |
Show key headers only | View raw
There are some basics about Python objects I don't understand. Consider this snippet: >>> class X: pass ... >>> x = X() >>> dir(x) ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] >>> x.foo = 11 And now I want to make a simple object in a shorter way, without declaring X class: >>> y = object() >>> dir(y) ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] >>> y.foo = 12 Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'object' object has no attribute 'foo' The attribute list is different now and there's no __dict__ and the object does not accept new attributes. Please explain what's going on.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
object().__dict__ Pavel Volkov <sailor@lists.xtsubasa.org> - 2014-04-23 09:39 +0400 Re: object().__dict_ Duncan Booth <duncan.booth@invalid.invalid> - 2014-04-23 08:56 +0000
csiph-web