- 论坛徽章:
- 0
|
#!/usr/bin/env python
# filename: workers.py
"""
Workers in a IT company named LiveGate
"""
class Workers:
"""This is a class of workers working in the company."""
def __init__(self,name,position,email,age,salary):
self.name = name
self.position = position
self.email = email
self.age = age
self.salary = salary
class ITWorkers(Workers):
"""This is a class of IT engineers."""
OS = 'WinNT'
def __init__(self,language,*av):
Workers.__init__(self,*av)
self.language = language
print 'oo %s' %(self.OS)
def work(self,n):
"""IT engineers should work."""
#w = ''
if self.position == 'web creator':
w = 'makes web site'
elif self.position == 'server administrator':
w = 'checks the trafic'
elif self.position == 'programmer':
w = 'writes programs'
print 'oo work %s,%s,%s' %(self.position,w,self.OS)
print '%s %s for %d,hours using %s on %s' %(self.name,w,n,self.language,self.OS)
#------------------------------------------
henley = ITWorkers('PHP','Henley','web creator','henley@livegates.com',32,700)
#thomas = ITWorkers('Python','Thomas','server administrator','thomas@livegates.com',37,900)
#gates = ITWorkers('C','Gates','Programmer','gates@livegates.com',42,1200)
henley.OS = 'Mac'
#thomas.OS = 'Linux'
if __name__ == '__main__':
henley.work(8)
# thomas.work(7)
# gates.work(10)
|
为什么 henley.work( 、 thomas.work(7) 、 gates.work(10)
类似的三个调用.gates.work(10)需要在work中先声明w.否则会出异常UnboundLocalError.而henley .thomas不会有异常。 |
|