printing the name of a class instance when it is created

Viewed 21
def find_name(var_name):
    for objname, oid in globals().items():
        if oid is var_name:
            return objname

class Class1:

    def __init__(self):

        print(find_name(self)," was created")

ojb = Class1()
#None  was created

ojb.__init__()
#ojb  was created

Is it possible when I create an object to print its name? after an object (obj in the example above) has been created, it will appear in the dictionary generated by the globals() function, but I need to print its name at the same time it is created, I don't want to create a method that I can call later. I need a trigger that triggers after an object has been created and can print its variable-name. I know it's absolutely useless what I want to do, but I want to do

0 Answers
Related