V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
walkingway
V2EX  ›  Python

请教关于Learning Python这本书一个例子上出现的问题

  •  
  •   walkingway · 2011-03-20 22:04:09 +08:00 · 4869 次点击
    这是一个创建于 4784 天前的主题,其中的信息可能已经有所发展或是发生改变。
    本人菜鸟一只,最近在看Learning Python这本入门书,书上的例子基本都会敲一遍,在看到第四章最后那个用户自定义类那里(大概105页),有个例子敲进去总提示:构造函数没有参数。请教一下各位大牛。


    >>> class Worker:
    def _init_(self,name,pay):
    self.name=name
    self.pay=pay
    def lastName(self):
    return self.name.split()[-1]
    def giveRaise(self,percent):
    self.pay*=(1.0+percent)
    这里构造完以后输入下面的第一条语句就出现错误了
    >>>bob=worker('Bob Smith',50000)

    具体错误
    Traceback (most recent call last):
    File "<pyshell#9>", line 1, in <module>
    bob=Worker('Bob smith',50000)
    TypeError: this constructor takes no arguments

    我用的是IDLE 2.7版本的python
    2 条回复    1970-01-01 08:00:00 +08:00
    darcy
        1
    darcy  
       2011-03-20 22:12:34 +08:00
    def _init_(self,name,pay):
    >>
    def __init__(self,name,pay):
    walkingway
        2
    walkingway  
    OP
       2011-03-20 22:34:01 +08:00
    @darcy 啊,我也发现了,多谢了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3351 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 12:01 · PVG 20:01 · LAX 05:01 · JFK 08:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.