推荐学习书目
› 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 · Mar 20, 2011 · 5726 views
    This topic created in 5676 days ago, the information mentioned may be changed or developed.
    本人菜鸟一只,最近在看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 replies  •  1970-01-01 08:00:00 +08:00
    darcy
        1
    darcy  
       Mar 20, 2011
    def _init_(self,name,pay):
    >>
    def __init__(self,name,pay):
    walkingway
        2
    walkingway  
    OP
       Mar 20, 2011
    @darcy 啊,我也发现了,多谢了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2398 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 113ms · UTC 12:32 · PVG 20:32 · LAX 05:32 · JFK 08:32
    ♥ Do have faith in what you're doing.