0
我是新來的python,我試圖運行命令行,但它失敗,錯誤TypeError: xeger() takes exactly 2 arguments (3 given)
。 我不明白原因,因爲我只發送兩個參數到xeger.xeger:out = xeger.xeger(pattern, limit)
。我知道self
已隱藏,但會自動添加到參數列表中,因此我已更改爲xeger.xeger(self, pattern, limit)
,並將函數簽名更改爲def generate(self, limit, pattern)
,但我仍然收到相同的錯誤。TypeError:xeger()需要2個參數(3給出)
import xeger
import click
@click.command()
@click.option('--limit', default=10, help='Number of chars to return')
@click.option('--pattern', prompt='pattern to match', help='regexp to match')
def generate(limit, pattern):
"""Simple program that receives a pattern and returns a matching string."""
out = xeger.xeger(pattern, limit)
click.echo('%s' % out)
if __name__ == '__main__':
generate()
運行和錯誤:
python rand.py --limit 230
pattern to match: asda
Traceback (most recent call last):
File "rand.py", line 13, in <module>
generate()
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 716, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File "rand.py", line 9, in generate
out = xeger.xeger(pattern, limit)
TypeError: xeger() takes exactly 2 arguments (3 given)