About 50 results
Open links in new tab
  1. How do I change the string representation of a Python class?

    Nov 6, 2015 · In Java, I can override the toString() method of my class. Then Java's print function prints the string representation of the object defined by its toString(). Is there a Python …

  2. python - How can I choose a custom string representation for a …

    I would like to create some kind of class decorator, so I can easily set custom string representations for my classes without having to write a metaclass for each of them.

  3. python - What is the difference between <class 'str'> and <type …

    Feb 5, 2017 · for ID in response: response is a string and enumerating it gives the characters in the string. Depending on the type of response you may want to use and HTML, JSON or other …

  4. Python: Reference to a class from a string? - Stack Overflow

    Apr 9, 2009 · How to use a string containing a class name to reference a class itself? Classes aren't special, they're just values contained in variables. If you've said: class X(object): pass in …

  5. Python: access class property from string - Stack Overflow

    I want to pass a string for the source variable in doSomething and access the class member of the same name. I have tried getattr which only works on functions (from what I can tell) as well as …

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

    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 …

  7. python - How to define a __str__ method for a class? - Stack …

    In Python, the object class serves as the root superclass for all the (new-style) classes. By default at least, applying str and repr to the "class instance" of any subclass of object produces the...

  8. Convert string to Python class object? - Stack Overflow

    Jul 24, 2009 · Given a string as user input to a Python function, I'd like to get a class object out of it if there's a class with that name in the currently defined namespace. Essentially, I want the …

  9. Does Python have a toString () equivalent, and can I convert a …

    153 In python, the str() method is similar to the toString() method in other languages. It is called passing the object to convert to a string as a parameter. Internally it calls the __str__() method …

  10. python - How to use __str__ function to return a string …

    May 23, 2022 · I have been tasked with creating an inventory manager in python, and one of the required is to define the following function within the class: __str__ - This function returns a …