Python Forum
General query regarding conversion of dict to class object - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: General query regarding conversion of dict to class object (/thread-15406.html)



General query regarding conversion of dict to class object - saisankalpj - Jan-16-2019

i have a object of type class<'postdata'>
This object contains details of a person
Now to convert this object to string.I have tried
json.dumps(object)
But this gives error like
object of type "postdata" is not json serializable
So i have tried
json.loads(json.dumps(object,default=lambda x: x.__dict__))
The output to above statement is dictionary
How to display this in initial format on console.I want type of output to be again
class<'postdata'>
Second question is
i have function
def abc():
   print("call in function abc")
so instead of writing "call in function abc",the function name should be taken dynamically,like what ever is function name ,it should print like calling that function,without us specifying abc