When you delete functions from a script, you need to make sure that the function you deleted is not being called later in the code.
For example, let's say your script looks like this:
def foo(x):
return x*x
def banana():
return "Peel"
def bar():
return "My " + banana()
i = int(raw_input("Please enter a number to be squared: "))
print foo(i) #prints the number you entered, squared
print banana() #prints "Peel"
print bar() #prints "My Peel"
So, if I only want the functionality of the functions bar()
and foo(x)
and I don't need to use the functionbanana()
, I can delete these functions. However, if I only delete the function banana()
, it will give an error, like so:
def foo(x):
return x*x
#deleted banana()
def bar():
return "My " + banana()
i = int(raw_input("Please enter a number to be squared: "))
print foo(i) #prints the number you entered, squared
print banana() #gives an error because banana() is not defined
print bar() #not executed because of the above error.
Let's delete print banana()
and see if that fixes it.
def foo(x):
return x*x
#deleted banana()
def bar():
return "My " + banana()
i = int(raw_input("Please enter a number to be squared: "))
print foo(i) #prints the number you entered, squared
#deleted print banana()
print bar() #error because the bar() function calls the deleted banana() function
This still does not work, because the bar()
function calls banana()
here:
def bar():
return "My " + banana()
When you delete a function, you need to delete every single call to that function, no matter where it is. If not, Python will try to call a function that doesn't exist and will give you an error. The correct example code for removing all traces of banana()
is below:
def foo(x):
return x*x
#deleted banana()
def bar():
return "My " + "Peel" # removed banana()
i = int(raw_input("Please enter a number to be squared: "))
print foo(i) #prints the number you entered, squared
#deleted print banana()
print bar() #prints "My Peel"
When you apply this to your code, make sure no functions you delete are called directly by any function you want to save (the crc32 function). In my example, if you wanted to keep the bar()
function, the banana()
function is actually necessary to run bar()
so you should not delete it.
In your code, the AddFile
method is what you call when you call GetFileCrc32()
. As you can see, FormatName()
and GetLastModifiedTime()
are both called as well. These functions are necessary for GetFileCrc32()
to work so you should not delete them.
def AddFile(self, filename):
filename = FormatName(filename)
mtime = GetLastModifiedTime(filename)
#
# Format is as following:
# unpacked_crc unpacked_size low_last_edit high_last_edit path
#
self.file_dict[filename.lower()] = [GetFileCrc32(filename),
"%d" % (os.path.getsize(filename)),
"%d" % (mtime >> 32),
"%d" % (mtime & 0xffffffff), filename]
# Sorted list no longer contains all files. Invalidate it.
self.file_list = None
I hope this helps!