Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97203

Re: Question re class variable

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 <python-python-list@m.gmane.org>
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 <jeanmichel@sequans.com>
Subject Re: Question re class variable
Date Tue, 29 Sep 2015 13:11:15 +0200
References <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> <mudr3k$soh$1@ger.gmane.org>
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 <mudr3k$soh$1@ger.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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.234.1443525084.28679.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Question re class variable plewto@gmail.com - 2015-09-29 02:27 -0700
  Re: Question re class variable alister <alister.nospam.ware@ntlworld.com> - 2015-09-29 10:00 +0000
    Re: Question re class variable John Gordon <gordon@panix.com> - 2015-09-29 14:44 +0000
      Re: Question re class variable Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-29 20:41 -0400
  Re: Question re class variable Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-09-29 12:40 +0200
    Re: Question re class variable Anssi Saari <as@sci.fi> - 2015-09-29 14:17 +0300
      Re: Question re class variable Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-09-29 14:02 +0200
      Re: Question re class variable Steven D'Aprano <steve@pearwood.info> - 2015-09-29 22:06 +1000
      Re: Question re class variable Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-29 08:21 -0400
  Re: Question re class variable jmp <jeanmichel@sequans.com> - 2015-09-29 13:02 +0200
  Re: Question re class variable jmp <jeanmichel@sequans.com> - 2015-09-29 13:11 +0200

csiph-web