Question re class variable

jmp jeanmichel at
Tue Sep 29 13:11:15 CEST 2015

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

import uuid

class GameObject:

   def __init__(self):
     self._id = None

   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

More information about the Python-list mailing list