I'm having a hard time figuring out the best way to resolve a name clash. Here's the gist of what I've got in front of me:
def clean():
# do some cleaning stuff
def build(clean=True):
if clean:
clean()
Oops.
For a few reasons, I do not want to change the API here. What is the best strategy to resolve this conflict? For now, I'm doing:
def clean():
# do some cleaning stuff
clean_alias = clean
def build(clean=True):
if clean:
clean_alias()
Which might be the best/only solution short of renaming things. I'm just wondering if there's a different way to reference the clean that's in the outer scope from within the body of the function?
Try:
globals()['clean']()
globals()
Return a dictionary representing the current global symbol table. This is always the dictionary of the current module (inside a function or method, this is the module where it is defined, not the module from which it is called).
Try adding a default argument, that binds the global clean function to a local variable.
def build(clean=True, cleanFn=clean):
if clean:
cleanFn()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With