I have sort of an interesting request here. Let's say I have a class called Object, which has two methods, func1() and func2(). The second method calls func1(), though I would like to be able to alter the function definition of func1() be able to differentiate between being called from within func2() from being called as a standalone method of my Object class, like so:
obj = Object()
obj.func1()
I could simply create two versions of the function (one private method, for func2() to use, and one public method for the user to be able to access; yes I know that in python there really is no such thing as private, but following I think the normal naming conventions, I can make it clear that it is meant to be an internal function only). But that would require a fair amount of redundancy, and is something I would like to try to avoid if at all possible. Is there any mechanism or strategy anybody can recommend for doing this type of thing?
I know, for example, that if I wanted my entire script object.py to execute a certain set of code if ran only as a standalone script (i.e. - it's not being imported at the top of another script), I would do:
if __name__ == "__main__":
...
code to run if standalone
...
I was wondering if there is a similar strategy for methods of a class.
func2can use when calling it to indicate "internal" use.debugattribute on the class. withself.debug = True, then print to the terminal, otherwise don't print.