Path: csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'none:': 0.05; 'subject:Question': 0.05; 'builtin': 0.07; '@property': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.13; 'jmp': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:class': 0.16; 'subject:variable': 0.16; 'wrote:': 0.16; 'cheers,': 0.22; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'host': 0.28; 'function': 0.28; 'print': 0.30; 'skip:_ 10': 0.32; 'class': 0.33; 'url:python': 0.33; 'add': 0.34; 'should': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'url:3': 0.60; 'your': 0.60; 'received:194': 0.61; 'charset:windows-1252': 0.62; 'url:uuid': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: jmp Subject: Re: Question re class variable Date: Tue, 29 Sep 2015 13:11:15 +0200 References: <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: paris.sequans.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1443525084 news.xs4all.nl 23795 [2001:888:2000:d::a6]:40986 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97203 On 09/29/2015 01:02 PM, jmp wrote: > class GameObject: > > @property > def id(self): > return id(self) #use the builtin id function > > print GameObject().id > > Cheers, > > JM I should add that until you don't serialize your object you're fine. If you need to serialize it, you may want to look at https://docs.python.org/3/library/uuid.html import uuid class GameObject: def __init__(self): self._id = None @property def id(self): if self._id is None: # make a UUID based on the host ID and current time self._id = uuid.uuid1() return self._id