Python Forum
How to print a global dictionary class properly - 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: How to print a global dictionary class properly (/thread-8841.html)



How to print a global dictionary class properly - 3dimensions - Mar-09-2018

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...>} ?


RE: How to print a global dictionary class properly - Larz60+ - Mar-09-2018

This code can't possibly run you have incomplete method definitions.


RE: How to print a global dictionary class properly - nilamo - Apr-18-2018

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.