Calling function with two different types of arguments in python -


i new python. came across weird case , not able figure out issue is. have 2 versions of function written in python :-

v1 -

def filelookup(fixedpath, version):     if version:         targetfile="c:\\null\\patchedfile.txt"     else:         targetfile="c:\\null\\vulfile.txt"  #some more code follows 

and v2 -

def filelookup(fixedpath, version):     if version:         print "ok"     else:         print "not ok"  #some more code follows 

where parameter fixedpath string entered , parameter version supposed integer value. 1st function (v1) not work expected, while tje second works perfectly. both times function called filelookup("c:\\dir\\dir\\", 1).

in 1st case error received :-

filelookup("d:\\celine\\assetserv\\", 1) exception: filelookup() takes 2 arguments (1 given) 

please let me know why 1st function throwing exception?

here actual code....

from system.io import *;  def filelookup(fixedpath, version): if version:     targetfile="c:\\null\\patchedfile.txt"; else:     targetfile="c:\\null\\vulfile.txt"; vulfilehandle=open(targetfile,"a+"); temp=fixedpath; if not directory.getdirectories(fixedpath):     files=directory.getfiles(fixedpath);     eachfile in files:         print eachfile;         hash = tools.md5(eachfile);         print hash;         vulfilehandle.write(eachfile+'\t'+hash+'\n'); else:     directory=directory.getdirectories(fixedpath);     folder in directory:         if vulfilehandle.closed:             vulfilehandle=open(targetfile,"a+");         fixedpath="";         fixedpath+=folder;         fixedpath+="\\";         vulfilehandle.close();         filelookup(fixedpath);     filess=directory.getfiles(temp);     eachfilee in filess:         if vulfilehandle.closed:             vulfilehandle=open(targetfile,"a+");         print eachfilee;         hashh = tools.md5(eachfilee);         print hashh;         vulfilehandle.write(eachfilee+'\t'+hashh+'\n'); if not vulfilehandle.closed:     vulfilehandle.close(); 

it recursive code print out hash of files in directory.

you have call "filelookup(fixedpath);" around line 26 or (just counted roughly) 1 argument sent in. definition doesn't allow that. send in version in call, or give default value version in definition.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -