Python Forum
How to print a global dictionary class properly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to print a global dictionary class properly
#1
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...>} ?
Reply
#2
This code can't possibly run you have incomplete method definitions.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Print controlled with global-var fmr300 3 1,405 Feb-05-2022, 03:09 PM
Last Post: fmr300
Question How to print each possible permutation in a dictionary that has arrays as values? noahverner1995 2 1,696 Dec-27-2021, 03:43 AM
Last Post: noahverner1995
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,883 Oct-03-2021, 05:16 PM
Last Post: Yoriz
  Syntax to print ndarray member of class containing ndarray pjfarley3 6 3,169 Jul-09-2020, 06:29 AM
Last Post: pjfarley3
  Dictionary VS Class JKBarnard 2 1,723 Dec-14-2019, 05:37 PM
Last Post: JKBarnard
  [split] Print JSON Dictionary to Excel? venukommu 1 2,251 Nov-15-2019, 09:33 PM
Last Post: micseydel
  Global variable does not seem to be global. Columbo 6 3,617 Jul-15-2019, 11:00 PM
Last Post: Columbo
  dictionary: print key/value with list(dict) comprehension wardancer84 4 2,926 Nov-14-2018, 03:14 PM
Last Post: wardancer84
  user input to select and print data from another class python TyTheChosenOne 6 4,056 Aug-30-2018, 05:53 PM
Last Post: TyTheChosenOne
  Can't get defined random integer to print properly? thb202 1 2,192 Aug-29-2018, 10:15 AM
Last Post: vndywarhol

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020