About 687,000 results
Open links in new tab
  1. python - How to make a class JSON serializable - Stack Overflow

    Sep 22, 2010 · It's unfortunate that the answers all seem to answer the question "How do I serialize a class?" rather than the action question "How do I make a class serializable?" These …

  2. Making a python user-defined class sortable, hashable

    What methods need to be overridden/implemented when making user-defined classes sortable and/or hashable in python? What are the gotchas to watch out for? I type dir({}) into my …

  3. When should I be using classes in Python? - Stack Overflow

    Oct 12, 2015 · In python the simple heuristic for when you should use a class comes down to whether or not your abstraction needs to be concerned with state. Abstractions that carry …

  4. 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 …

  5. syntax - Python: Make class iterable - Stack Overflow

    Mar 25, 2011 · Is it possible to make a python class iterable itself using the standard syntax? That is, I'd like to be able to iterate over all of a class's attributes using for attr in Foo: (or even if attr …

  6. How to make an immutable object in Python? - Stack Overflow

    Python usually relies on library implementers and library users being consenting adults, and instead of really enforcing an interface, the interface should be clearly stated in the …

  7. How can I implement a tree in Python? - Stack Overflow

    You can create a Tree data structure using the dataclasses module in Python. The iter method can be used to make the Tree iterable, allowing you to traverse the Tree by changing the order …

  8. python - How to build a basic iterator? - Stack Overflow

    In Python, sequences are iterable too so one way to make an iterable class is to make it behave like a sequence, i.e. give it __getitem__ and __len__ methods. I have tested this on Python 2 …

  9. How do I use a class method without passing an instance to it?

    Nov 26, 2024 · Functions related to a class but that do not require either a class or an instance should be static methods Functions that are related to a class, and will need the class for …

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

    Jan 25, 2011 · According to my tests with Python 3, for immutable objects, like tuples or strings, it returns the same object (because there is no need to make a shallow copy of an immutable …