[Tutor] Class Construction question

Chris Davidson cxd401@psu.edu
Mon Nov 11 19:40:02 2002


Hey everyone,

	Well that copy and pasting issue was just that, a copy and paste issue.
The code i was working with didn't have the shebang and i was doing
./Person.py, which was the first problem, and the second problem is with
arguments.

Traceback (most recent call last):
  File "./Person.py", line 19, in ?
    testing = Person("Chris")
  File "./Person.py", line 5, in __init__
    self.setPhone(Name)
TypeError: setPhone() takes exactly 1 argument (2 given)

Here is the modified code:

#!/usr/bin/python
class Person:
    def __init__(Name):
        self.setPhone(Name)
    def setPhone(Name):
        self.PhoneNumber = string
    def setName(string):
	self.FirstName = string
    def getName():
        return self.FirstName    
    def getPhoneNumber():
        return self.PhoneNumber
    
testing = Person("Chris")
print testing.getName()
testing.setName("testing")
print testing.getName()


Sorry for being such a pain, just i am trying to learn classes the
python way and my C++ skills are getting in the way. Anyone know good
class creation documentation for python. I have yet to find any real
good ones.

Thank you again everyone,
Chris