Using object id as a hash for objects in Python

Is it wise to use the object id as a hash key (via. the __hash__) to be able to hash an otherwise mutable object for a single instance of a program? Using the object attributes would be nicer but they're all mutable and can change.

This occurred to me while looking at and I'm wondering if it's wise.


Yes, as long as you also define __eq__ (and presumably __ne__!-) consistently with that. IOW, it's fine, as long as you're fine with a==b meaning exactly the same as a is b!-)

Need Your Help

Calling constructor from another constructor?

c++ oop constructor

I created three classes: Shape (base class) , Rectangle and Square. I tried to call Shape's constructor from Rectangle's and Square's constructors, but the compiler shows errors.

ERLANG - Timing Applications

erlang performance timing

I am interested in benchmarking different parts of my program for speed. I having tried using info(statistics) and erlang:now()

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.