Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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; 'subject:Python': 0.06; 'method,': 0.07; 'also:': 0.09; 'attributes,': 0.09; 'content- type:multipart/signed': 0.09; 'filename:fname piece:signature': 0.09; 'variables.': 0.09; 'def': 0.15; '(at)': 0.16; '(dot)': 0.16; '__init__': 0.16; 'content-type:application/pgp-signature': 0.16; 'filename:fname piece:asc': 0.16; 'filename:fname:signature.asc': 0.16; 'received:209.85.213.174': 0.16; 'received:mail-yx0-f174.google.com': 0.16; 'subject:OOP': 0.16; 'this:': 0.16; 'wrote:': 0.16; 'subject:question': 0.18; 'cc:no real name:2**0': 0.20; 'blog:': 0.21; 'subject:help': 0.22; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'dictionary': 0.23; 'pm,': 0.24; 'code': 0.25; 'creating': 0.25; "i'm": 0.27; 'looks': 0.29; 'cc:addr:gmail.com': 0.30; 'hansen': 0.30; 'sub': 0.30; 'class': 0.30; 'received:24': 0.32; 'hi,': 0.32; 'objects': 0.32; 'to:addr:python-list': 0.33; '...': 0.34; 'skip:- 40': 0.35; 'trouble': 0.35; 'class.': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'subject:with': 0.39; 'define': 0.39; 'to:addr:python.org': 0.39; 'your': 0.61; 'custom': 0.61; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'mail:': 0.73; '11:47': 0.84; 'dict()': 0.84; 'so:': 0.84; 'url:io': 0.93 Sender: Ixokai Date: Mon, 05 Sep 2011 00:07:45 -0700 From: Stephen Hansen MIME-Version: 1.0 To: python-list@python.org Subject: Re: Need help with simple OOP Python question References: In-Reply-To: X-Enigmail-Version: 1.3.1 OpenPGP: id=555B1FE5; url=http://id.ixokai.io/pub.asc Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig131D1A4F14011C799AC6DA88" Cc: krille012@gmail.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: me+list/python@ixokai.io 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315206481 news.xs4all.nl 2414 [2001:888:2000:d::a6]:50109 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12759 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig131D1A4F14011C799AC6DA88 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 9/4/11 11:47 PM, Kristofer Tengstr=F6m wrote: > Hi, I'm having trouble creating objects that in turn can have custom > objects as variables. The code looks like this: >=20 > --------------------------------------------- >=20 > class A: > sub =3D dict() You are sharing this single "sub" dictionary with all instances of your A class. If you want to define instance-specific attributes, define them in the __init__ method, like so: class A: def __init__(self): self.sub =3D dict() def sub_add(self, cls): obj =3D cls() self.sub[obj.id] =3D obj --=20 Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ --------------enig131D1A4F14011C799AC6DA88 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) iQEcBAEBAgAGBQJOZHVKAAoJEKcbwptVWx/l3+4H/3abOlp0rAR0HRYdxsDGw6HP uZN9+H6mkw/NqgVsD5yxTkE+l1axvq6w0GmFsHBOm9Xx9dbnOpzAMuAENEPgxg5o LXTwWVQePHnk2mr9xdwSkL5L/8cRqegzPaLVs085iMlnQUHkgO+l13grQD4Wnh6d rXnV/Ah1y2I2iGO1bM382imEmGDkIUpM8tPdpnUyCVz1rI7LjsmvLoBspKKbT1Ip qr8+1wvH9OINUff4YHBtIvST/wRhxQNYYOb7q6JcR88bGPhUXDNI73/eyVgIcGYf Buft1Ieyl+RsweoEuGsXgGh+GuJN+ISBtlrrEFglSDPfsvHyP8jfeLisxjPX+IQ= =tVRh -----END PGP SIGNATURE----- --------------enig131D1A4F14011C799AC6DA88--