Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python exception:"TypeError: main() got an unexpected keyword argument 'debug'" but IFF the module is run via scheduledTask on Windows XP SP2

Running Python 2.5 on Windows XP SP2.

When I run a Python script that calls a user-defined module called Zipper.py (basically a wrapper for a zipfile) using a Windows scheduledTask I get this exception:

Traceback (most recent call last):
File "C:\PythonScripts\ZipAndSendEOD-Reports.py", line 78, in main
Zipper.main([report],f, debug=True) #[:-4] + "_" + str(x) + ".zip")
TypeError: main() got an unexpected keyword argument 'debug'

The odd thing is that if I simply open the file in IDLE and hit 'F5', it runs flawlessly.

I'm sure I left out some pertinent information, please let me know what you need.

Zipper.py looks like this:

import zipfile

def main(archive_list=[],zfilename='default.zip', debug=False):
    if debug:    print 'file to zip', zfilename
    zout = zipfile.ZipFile(zfilename, "w", zipfile.ZIP_DEFLATED)
    for fname in archive_list:
        if debug:    print "writing: ", fname
        zout.write(fname)
    zout.close()

if __name__ == '__main__':
    main()

EDIT: I added the following two lines of code to the calling function, and it now works.

f =  open(logFile, 'a')
f.write(Zipper.__file__)

Can you explain THAT to me?

like image 362
Ramy Avatar asked Nov 16 '10 22:11

Ramy


1 Answers

As Paul said, you're probably running a different version of Zipper.py - I would print out Zipper.__file__ and then if you need to debug, print out sys.path to see why it's finding a different file.

like image 176
David Fraser Avatar answered Oct 12 '22 22:10

David Fraser