Python Forum
How to check if class instance exists in a list of class instance objects?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to check if class instance exists in a list of class instance objects?
#21
(May-26-2018, 08:22 PM)buran Wrote: instances of classes and instances of objects???

Classes in Python are objects too
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#22
Of course everything is an object, no doubt about that!!! "
That's exactly why I don't get the difference you make between instances of classes and instances of objects...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#23
(May-27-2018, 03:58 AM)buran Wrote: Of course everything is an object, no doubt about that!!! "
That's exactly why I don't get the difference you make between instances of classes and instances of objects...

Does "object of un-instantiated class" sounds better? If that is still unclear

Output:
In [31]: type(list().__class__) Out[31]: type In [32]: type(dict().__class__) Out[32]: type In [33]: type('abc'.__class__) Out[33]: type
Classes itself are objects of type .... type, which is a trinity Cool of function, metaclass and class factory.

Even if object is un-hashable, the class of that object will be always hashable (unless you implement some crazy hack that will make it unhashable - if that is possible). Again, look at my code: I was not saving objects in a set - I was saving classes


PS Maybe, a little demonstration will help

Output:
In [37]: class A: ...: def __init__(self, name): ...: self.name = name ...: In [38]: set([A('volcano63').__class__, A('buran').__class__, A('sonicblind').__class__]) Out[38]: {__main__.A}
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#24
(May-27-2018, 04:32 AM)volcano63 Wrote: Does "object of un-instantiated class" sounds better?
Yes, now I see what you mean
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Copying methods to effect the new owner instead of the old instance Daniel285 2 268 Jun-03-2024, 07:58 AM
Last Post: Gribouillis
  [split] Class and methods ebn852_pan 15 945 May-23-2024, 11:57 PM
Last Post: ebn852_pan
  [SOLVED] [listbox] Feed it with dict passed to class? Winfried 3 386 May-13-2024, 05:57 AM
Last Post: Larz60+
  Class and methods Saida2024 2 358 May-13-2024, 04:04 AM
Last Post: deanhystad
  How does this code create a class? Pedroski55 6 721 Apr-21-2024, 06:15 AM
Last Post: Gribouillis
  class definition and problem with a method HerrAyas 2 409 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  Printing out incidence values for Class Object SquderDragon 3 483 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  class and runtime akbarza 4 543 Mar-16-2024, 01:32 PM
Last Post: deanhystad
  Help with to check an Input list data with a data read from an external source sacharyya 3 619 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  Operation result class SirDonkey 6 731 Feb-25-2024, 10:53 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020