About 227,000 results
Open links in new tab
  1. python - How can I create an object and add attributes to it?

    May 13, 2010 · I want to create a dynamic object in Python and then add attributes to it. This didn't work: obj = object() obj.somefield = "somevalue" AttributeError: 'object' object …

  2. How can I dynamically create derived classes from a base class

    The general answer on how to "dynamically create derived classes from a base class" in Python is a simple call to type passing the new class name, a tuple with the baseclass (es) and the …

  3. python - Create new object (class instance) from object method

    I want to be able to create a new instance of an object by calling a method on an already instantiated object. For example, I have the object: organism = Organism() I want to be able to …

  4. how to dynamically create an instance of a class in python?

    Create a class instance from a full path to a class constructor :param class_str: module name plus '.' plus class name and optional parens with arguments for the class's

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

  6. Is there a benefit to defining a class inside another class in Python?

    Sep 17, 2008 · I don't know Python, but your question seems very general. Ignore me if it's specific to Python. Class nesting is all about scope. If you think that one class will only make …

  7. python - Create instance of class in another class (with generic ...

    28 I'm learning python via book and internet and I'm stuck on a class issue. 2 questions: How do I create an instance of one class in another (separate) class? How do I pass variables between …

  8. How to create a new instance from a class object in Python

    May 8, 2011 · 113 I need to dynamically create an instance of a class in Python. Basically I am using the load_module and inspect module to import and load the class into a class object, but …

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

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