0

I just wanted to try some classes then I am stuck in Basics ..My code is below :

class Prob():
    def _init_(self):
        self._count = 0
    def _ProbCal(self):
        print(self._count)
d = Prob()
d._ProbCal()

error is :

Traceback (most recent call last):
  File "ProbCalculation.py", line 8, in <module>
    d._ProbCal()
  File "ProbCalculation.py", line 6, in _ProbCal
    print(self._count)
AttributeError: 'Prob' object has no attribute '_count'
1
  • 1
    def __init__(self) .. Double underscore Commented Jan 26, 2016 at 15:40

2 Answers 2

1

Your __init__ function requires double underscores at the start and end of the method name:

class Prob():
    def __init__(self):
        self._count = 0

    def _ProbCal(self):
        print(self._count)

d = Prob()
d._ProbCal()
Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much , I feel so silly for this stupid mistake
0

_init_ Must have double underscores like so:

class Prob():
    def __init__(self):
        self._count = 0
    def _ProbCal(self):
        print(self._count)
d = Prob()
d._ProbCal()

1 Comment

thank you very much , I feel so silly for this stupid mistake

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.