Python Forum

Full Version: How to print a global dictionary class properly
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Let's say I have the following class and we know that the code is working properly:

class Test:
    global_dictionary = {}

    def __init__ (self):
        #Initializations here

    def add_to_global_dictionary (self, username):

    def print_global_dictionary (self):
        print (Test.global_dictionary)

test = Test()
test.add_to_global_dictionary("3dimensions"):
test.print_global_dictionary()
Why is the dictionary printed like this: {'3dimensions': <__main__.Test object at 0x...>} ?
This code can't possibly run you have incomplete method definitions.
add_to_global_dictionary, if you had included the actual code, is probably adding username as the key, and self as the value.

And that should have been obvious based on the output. Next time, share the code, not bits and pieces, so other people can look at what you're asking about.