Add parameter to __init__ in function

387 Views Asked by At

Here is the original main.py code

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

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

that initializes this Downloader class

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

When I add an extra argument 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 produces this error

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'

How do I correctly add an argument?

0

There are 0 best solutions below