I am new to Python. I came across a weird case and am not able to figure out what the issue is. I have 2 versions of a 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 the parameter fixedPath is a string that is entered and the parameter version is supposed to be an integer value. The 1st function (v1) does not work as expected, while tje second works perfectly. Both the times the function is called as fileLookUp("c:\\dir\\dir\\", 1).
In the 1st case the error received is :-
fileLookUp("D:\\Celine\\assetSERV\\", 1)
Exception: fileLookUp() takes exactly 2 arguments (1 given)
Please let me know why is the 1st function throwing the exception?
Here is the 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);
for eachFile in files:
print eachFile;
hash = Tools.MD5(eachFile);
print hash;
vulFileHandle.write(eachFile+'\t'+hash+'\n');
else:
directory=Directory.GetDirectories(fixedPath);
for folder in directory:
if vulFileHandle.closed:
vulFileHandle=open(targetFile,"a+");
fixedPath="";
fixedPath+=folder;
fixedPath+="\\";
vulFileHandle.close();
fileLookUp(fixedPath);
filess=Directory.GetFiles(temp);
for 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 is simply a recursive code to print out the hash of all files in a directory.
IndentationError.