About 308,000 results
Open links in new tab
  1. python - How to print instances of a class using print ... - Stack Overflow

    As Chris Lutz explains, this is defined by the __repr__ method in your class. From the documentation of repr(): For many types, this function makes an attempt to return a string that would yield an object …

  2. class - Why do Python classes inherit object? - Stack Overflow

    Apr 9, 2022 · The answer to this question (while simple) is quite difficult to find. Googling things like "python object base class" or similar comes up with pages and pages of tutorials on object oriented …

  3. class Classname(object), what sort of word is 'object' in Python?

    Apr 6, 2012 · 32 object is a (global) variable. By default it is bound to a built-in class which is the root of the type hierarchy. (This leads to the interesting property that you can take any built-in type, and use …

  4. python - How to check whether a variable is a class or not? - Stack ...

    Dec 28, 2008 · I was wondering how to check whether a variable is a class (not an instance!) or not. I've tried to use the function isinstance (object, class_or_type_or_tuple) to do this, but I don't know what …

  5. python - How can I check if an object has an attribute? - Stack Overflow

    How do I check if an object has some attribute? For example: >>> a = SomeClass() >>> a.property Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: SomeClass …

  6. python - Serializing class instance to JSON - Stack Overflow

    A simple solution would be to call json.dumps() on the .__dict__ member of that instance. That is a standard Python dict and if your class is simple it will be JSON serializable.

  7. python - Determine the type of an object? - Stack Overflow

    2398 There are two built-in functions that help you identify the type of an object. You can use type() if you need the exact type of an object, and isinstance() to check an object’s type against something. …

  8. python - List attributes of an object - Stack Overflow

    If you want to learn about what methods and such exist for an object to understand how it works, use help. help(a) will show you a formatted output about the object's class based on its docstrings.

  9. How can I create a copy of an object in Python? - Stack Overflow

    Jan 25, 2011 · To get a fully independent copy of an object you can use the copy.deepcopy() function. For more details about shallow and deep copying please refer to the other answers to this question …

  10. python - How to create a list of objects? - Stack Overflow

    Aug 15, 2020 · How do I go about creating a list of objects (class instances) in Python? Or is this a result of bad design? I need this cause I have different objects and I need to handle them at a later stage, s...