About 1,080,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. What is the best way of implementing a singleton in Python?

    Jun 10, 2020 · This process is the same as Python asking a class what to do by calling __getattr__ when you reference one of its attributes by doing myclass.attribute. A metaclass …

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

  4. python - How to print instances of a class using print ... - Stack …

    A simple decorator @add_objprint will help you add the __str__ method to your class and you can use print for the instance. Of course if you like, you can also use objprint function from the …

  5. python - Class accessible by iterator and index - Stack Overflow

    Mar 19, 2019 · My class implements an iterator so I can do: for i in class(): But I want to be able to access the class by index as well: class()[1] How can I do that?

  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. "Private" (implementation) class in Python - Stack Overflow

    I am coding a small Python module composed of two parts: some functions defining a public interface, an implementation class used by the above functions, but which is not meaningful …

  8. python - How to make a custom object iterable? - Stack Overflow

    I have a list of custom-class objects (sample is below). Using: list (itertools.chain.from_iterable (myBigList)) I wanted to "merge" all of the stations sublists into one big list.

  9. 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.

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