Simply because it didn't occur to me. So now I have
>>> class A: pass
...
>>> d = {A:[A(),A(),A()]}
>>> a = d[A].pop()
>>> a
<__main__.A instance at 0x00F09A58>
>>>
Thanks all!
/Joakim
--
http://mail.python.org/mailman/listinfo/python-list
In article <[EMAIL PROTECTED]>,
"Joakim Storck" <[EMAIL PROTECTED]> wrote:
> So I guess it might be a little bit less unwise to use id() instead
> then...
Why don't you use the class objects themselves as dict keys?
Just
--
http://mail.python.org/mailman/listinfo/python-list
So I guess it might be a little bit less unwise to use id() instead
then...
/Joakim
--
http://mail.python.org/mailman/listinfo/python-list
Mick Krippendorf wrote:
In Python there seems to be no guarantee that different objects also
have different hash values.
Well, it's true that you can override the __hash__ method to do whatever
you want, but I believe the default for class __hash__ methods is to
return the class id, which should
Joakim Storck wrote:
> [...] the hash values of classes will be used as
> keys in a dictionary that serve as an object pool. [...]
That does seem unwise (as Teal'c would have uttered). The spec says:
hash( object)
Return the hash value of the object (if it has one). Hash values are
in
Thanks!
Not so strange I think, the hash values of classes will be used as keys
in a dictionary that serve as an object pool.
Sorry about the double posting, I got a 'server error' message the
first time, so I figured it hadn't gone trhough.
/Joakim
--
http://mail.python.org/mailman/listinfo/p
Joakim Storck wrote:
> Is there any way that I can find the hash value of a class from an
> instance?
>
You only had to post the question once. It seems a strange thing to want,
but just do:
hash(a.__class__)
--
http://mail.python.org/mailman/listinfo/python-list
Hello,
Is there any way that I can find the hash value of a class from an
instance?
>>> class A:
... pass
...
>>> a = A()
>>> hash(A)
10782976
>>> hash(a)
12251904
>>>
What I want is a function that returns the value of 'hash(A)':
> a.getHashOfClass()
10782976
Is this possible?
/Joakim
--
Hello,
Is there any way that I can find the hash value of a class from an
instance?
>>> class A:
... pass
...
>>> a = A()
>>> hash(A)
10782976
>>> hash(a)
12251904
>>>
What I want is a function that returns the value of 'hash(A)':
> a.getHashOfClass()
10782976
Is this possible?
/Joakim
--