0

I am working with mongodb in python and want to define some functions. One function needs a collection object as well as its name represented as string. However for the user its the same name. The only difference is, that the user has to define the name one time as obejct as well as string, like

myfunc(object, "object")

However, I want to change this and want to convert the object internally into a string like

myfunc(object)

When I use str(), the values of the string are show but not the string-representation of the object like "object".

So, is there a way to convert the object name directly into string?

Pluxyy
  • 95
  • 2
  • 11
  • what do you mean by object name? like if i have a class called Test() and a make a test object like `x = Test(some stuff)`. would you want to know that its a test, or that the var is x? – Jacobr365 Sep 28 '17 at 15:51
  • 1
    Do you mean something like: `object.__class__.__name__`? – Christian Dean Sep 28 '17 at 15:51
  • I have an object of a class and the object is called thing. I want to convert thing into a string representation. .name is not a method of the class. Because I need it as string representation to search for the object in a predefined tuple. You can compare it to the way we translate numbers to string with str(number). This way we get a string representation of a number. I want just a string representation of the instance. – Pluxyy Sep 28 '17 at 16:04

0 Answers0