You can't check what parameter is passed to func1 using this -
def func2(func1):
If a is not None:
.......
In this, You are just passing the func1 to func2 as parameter. Nowhere has it been explicitly specified what parameter func1 will be using. So, You will have to decide what you are going to pass to func1 inside your func2 code.
Maybe you are looking for something like this -
def func2(func1,a=None):
if a != None: # When a non - None parameter is passed
func1(a)
else :
# Something when a is none
Here, you can check what parameter is going to be passed to func1 since during the call to func2, you will have to specify either 1 or 2 arguments. a is set to None by default. If a 2nd parameter is not passed to func2, it means that no parameter for func1 has been given. This means func1 was meant to be called without a parameter ( or using the default set parameter value ).
Or maybe you are looking to do something like this -
def func1(a=None):
func1.a = a
print(a)
def func2(f):
f(2) # Called with a paramter, so f.a will not be None
print(f.a)
f() # Called without a param, so f.a will be None
print(f.a)
func2(func1)
Output :
2
2
None
None
Here, the function object will set the parameter passed to it as its object and then once it called, depending on what the value of func1.a is, you can get what was the value with which the function was called last time. You can modify the above snippet for what you asked in question as -
def func1(a=None):
func1.a = a
def func2(f):
if f.a is not None:
print("Last call with paramter - " + str(f.a))
else :
print("Last Function call was made without a paramter")
func1()
func2(func1)
func1(2)
func2(func1)
Output :
Last Function call was made without a paramter
Last call with paramter - 2
Hope this helps !