0

Hi,

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

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

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.

4
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by bumsfeld
0

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()
s.show()
0

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.