I have a file named demo.py.The contents of the file are:

class a:
          def show(self):
                        print a.name

When I execute the file it gives me the following error:

"<bound method a.show of <__main__.a instance at 0x009D58C8>>"

Kindly advice on how to proceed with it.

Recommended Answers

All 3 Replies

I would use self to carry the variable name within the class. Also by convention class names start with an uppercase letter.

class A:
    name = "swapna"
    def show(self):
        print self.name
s = A()

the code u have sent I typed as it is in the script and it worked without any error

Looks more like message from lint-filter, telling you to use self. Some of the commercial IDEs have filters built in.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.