How to create a global variable inside a class. I created a global variable but it emulate nameerror

class A:

diction = {}

def some(self):

    global diction

    diction = {"name": "some",

               "id": "someid",

               "prof": "somth",

               }

    return diction

def some1(self):

    if diction["name"] == "some":

        print("one")

    else:

        print("none")

A.some1(A)

NameError: name ‘diction’ is not defined

Are you trying to share the same dictionary across instances? Then something like this might work.

class A:
  diction = {}
  def some(self):
    self.diction["name"] = "some"
  def some1(self):
    if self.diction["name"] == "some":
      print("one")
    else:
      print("none")

instance1 = A()
instance1.some()
instance1.some1() # prints: one
instance2 = A()
instance2.some1() # prints: one