0

Facing the error as :

AttributeError: 'function' object has no attribute 'd'.

how to access the dictionary?

code:

    class A:
    @staticmethod
    def test():
        d = {}
        d['a'] = 'b'
        print d
    @staticmethod
    def test1():
        d1 = {}
        d1['a'] = 'c'
        if (A.test.d['a'] == A.test1.d1['a']):
            print "yes"

        else:
            print "Oh No!!"
A.test()
A.test1()
John Dvorak
  • 26,799
  • 13
  • 69
  • 83
thor
  • 1
  • 1

1 Answers1

1

Check out this on the matter of static variables in Python.

You should be able to sort it out using A.d and A.d1 whenever you wish to use the static variables. Note that, as you have them, they are local to test and test1, respectively. If you want them to be static, you have to declare them inside the class scope, but not within any function definition.

Community
  • 1
  • 1
snowingheart
  • 120
  • 9
  • Thanks, as u You told i had declared it as local variable,butt after declaring as a global variable outside function but inside the class & accessed the global variable inside any function by A.d['a'] == d1['a'] instead of above mentioned in the code & its working fine. – thor Mar 07 '13 at 08:27
  • 1
    @thor If this answer solved your problem, you should accept it by clicking the check mark next to it. This will let other people who might be facing a similar issue know that the answer is likely to help them as well. It will also reward the person who posted it for their efforts in helping you. – itsjeyd Apr 09 '14 at 16:45