菜鸟一个课本实例的有关问题
发布时间:2011-06-29 20:10:21 文章来源:www.iduyao.cn 采编人员:星星草
初学者一个课本实例的问题
请教坛子里的高手们,本人最近在学习Python,做实例做到如下一个,但是编译总是说抽象方法不能调用,不知道问题处在哪里,请大家帮我看看,谢谢!
'''
EmployeeModule.py
'''
class Employee:
""" """
def __init__(self,first,last):
"""
"""
if self.__class__==Employee:
raise NotImplementedError,"Cannot create object of class Employee"
self.firstName=first
self.lastName=last
def __str__(self):
""" """
return "s% %s"(self.firstName,self.lastName)
def _checkPositive(self,value):
""" """
if value<0:
raise ValueError,"Attribute value (%s) must be positive" % value
else:
return value
def earnings(self):
""" """
raise NotImplementedError,"Cannot call abstract method"
#===============================================
'''
BossModule.py
'''
from EmployeeModule import *
class Boss(Employee):
def __init__(self,first,last,salary):
Employee.__init__(self,first,last)
self.weekSalary=self._checkPositive(float(salary))
def eranings(self):
return self.weekSalary
def __str__(self):
return "%17s,%s"%("Boss",Employee.__str__(self))
#======================================
'''
CommissionWorkerModule.py
'''
from EmployeeModule import *
class CommissionWorker(Employee):
def __init__(self,first,last,salary,commission,quantity):
Employee.__init__(self,first,last)
self.weekSalary=self._checkPositive(float(salary))
self.commission=self._checkPositive(float(commission))
self.quantity=self._checkPositive(quantity)
def eranings(self):
return self.salary+self.commission*self.quantity
def __str__(self):
return "%17s,%s"%("Commission Worker",Employee.__str__(self))
#==================================================
'''
HourlyWorkerModule.py
'''
from EmployeeModule import *
class HourlyWorker(Employee):
def __init__(self,first,last,wage,hours):
Employee.__init__(self, first, last)
self.wage=self._checkPositive(float(wage))
self.hours=self._checkPositive(float(hours))
def earnings(self):
if self.hours<=40:
return self.wage*self.hours
else:
return 40*self.wage+(self.hours-40)*self.wage*1.5
def __str__(self):
return "%17s,%s"%("Hourly Worker",Employee.__str__(self))
#==================================================
'''
Created on 2011-12-15
@author: peter
'''
from EmployeeModule import *
class PieceWorker(Employee):
def __init__(self,first,last,wage,quantity):
Employee.__init__(self, first, last)
self.wagePerPiece=self._checkPositive(float(wage))
self.quantity=self._checkPositive(quantity)
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
能不能找到支持 python 2.6 2.7 3.x 版本的 mod_python 呢?
http://archive.apache.org/dist/httpd/modpython/win/3.3.1/
我在...
-
windows下安装apache + python + django + mod_wsgi.so
对应版本:
Apache:Apache HTTP Server (httpd) 2.2.19
Python:Python2.7
Dja...
-
手工执行python3程序没问题,放在cron里面就不执行有中文的代码,高手帮忙啊。急!
先介绍下基本情况
环境: redhat Python3.2
目的:定...
-
PYTHON用什么编辑器?
是用自带的IDLE不?
------解决方案--------------------
看下国外的Python用户都用什么吧:
http://jobs.pyth...
-
为什么在python25中输入下面的代码是错误的??求大神!
if 1 < 0:
print '”x” must be atleast 0!'
------解决方案-----...
-
pyhthon zipfile获取压缩文件列表后怎样打开其中某个文件?
如题。似乎ZipFile没有open操作..
zCmfile = zipfile.ZipFile(target...
-
本人菜鸟一个,哪位大神帮我解释一下下面两段
import sys
print >> sys.stderr, 'Fatal error: invalid input!'
import sys
...
-
老王的python学习网站!推荐!
http://blog.csdn.net/hendom/article/details/7173207
很不错的python学习网站。
http://www.cnpyt...
-
myeclipse里导入python项目
初学python,我在myeclipse里导入已有项目,选择路径后为什么没出现该项目,这项目不应该有问题啊,我用的是m...
-
安装PyQt的问题?
今天在ubuntu下安装了PyQt-x11-gpl-4.9,但是我按照《getting started with PyQt》上的一个例子
import sys
from ...