Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97203
| From | jmp <jeanmichel@sequans.com> |
|---|---|
| Subject | Re: Question re class variable |
| Date | 2015-09-29 13:11 +0200 |
| References | <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> <mudr3k$soh$1@ger.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.234.1443525084.28679.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Find similar | Unroll 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