在函数中为__init__添加参数

时间:2013-12-03 14:16:40

标签: python python-2.7 constructor kwargs

以下是原始main.py代码

kwargs = {
    "ffmpeg":    args.ffmpeg,
    "rtmpdump":  args.rtmpdump,
    "swfrender": args.swfrender,
    }

with presentation.Downloader(pres, **kwargs) as builder:

初始化此Downloader

class Downloader(object):
    def __init__(self, presentation, overwrite="-n", ffmpeg="ffmpeg", rtmpdump="rtmpdump", swfrender="swfrender"):
        self.presentation = presentation
        self.ffmpeg = ffmpeg
        self.rtmpdump = rtmpdump
        self.swfrender = swfrender

当我添加额外的参数overwrite

    kwargs = {
        "ffmpeg":    args.ffmpeg,
        "rtmpdump":  args.rtmpdump,
        "swfrender": args.swfrender,
        "overwrite": "-y" if args.overwrite else "-n",
        }

    with presentation.Downloader(pres, **kwargs) as builder:

class Downloader(object):
    def __init__(self, presentation, overwrite="-n", ffmpeg="ffmpeg", rtmpdump="rtmpdump", swfrender="swfrender", overwrite="-n"):
        self.presentation = presentation
        self.ffmpeg = ffmpeg
        self.rtmpdump = rtmpdump
        self.swfrender = swfrender
        self.overwrite = overwrite

python产生此错误

Traceback (most recent call last):
  File "infoqscraper/main.py", line 374, in <module>
    sys.exit(main())
  File "infoqscraper/main.py", line 369, in main
    module.main(infoq_client, args.module_args)
  File "infoqscraper/main.py", line 191, in main
    return command.main(infoq_client, args.command_args)
  File "infoqscraper/main.py", line 307, in main
    with presentation.Downloader(pres, **kwargs) as builder:
TypeError: __init__() got an unexpected keyword argument 'overwrite'

如何正确添加参数?

0 个答案:

没有答案