Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
something wrong: class
#1
the code:
from __future__ import print_function
total = 1
class Classy:
    total = 0
    def __init__(self):
        return
    def add(self,a):
        p = self.total
        self.total += a
        return p
if __name__ == '__main__':
    c = Classy
    print('c =',repr(c))
    print(dir(c))
    for n in range(3):
        x = c.add(8)
        print('x =',repr(x))
i ran it under python3:
Output:
lt1/forums /home/forums 48> py3 min1.py c = <class '__main__.Classy'> ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'add', 'total'] Traceback (most recent call last):   File "min1.py", line 16, in <module>     x = c.add(8) TypeError: add() missing 1 required positional argument: 'a' lt1/forums /home/forums 49>
what did i miss in learning about classes?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
something wrong: class - by Skaperen - Feb-19-2017, 05:24 AM
RE: something wrong: class - by Larz60+ - Feb-19-2017, 06:18 AM
RE: something wrong: class - by Skaperen - Feb-19-2017, 08:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,795 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Class Instances called in the wrong order IanIous 4 2,961 Mar-06-2020, 02:16 PM
Last Post: IanIous
  python gives wrong string length and wrong character thienson30 2 3,104 Oct-15-2019, 08:54 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020