'Retrieve original argument name from args

How in this case I can print the original argument name?

def test_if_null(*args: Any) -> None:   
    for argument in args:
        if not argument:
           print(original_argument_name)
q='t'
w=None
e='e'
    
test_if_null(q,w,e)

expect to be printed 'w'



Solution 1:[1]

You can use **kwargs

def test_if_null(**kwargs: Any) -> None:   
    for name, arg in kwargs.items():
        if not arg:
           print(name)
q='t'
w=None
e='e'
    
test_if_null(q=q,w=w,e=e) # Prints w

In this case kwargs is a dictionary of all the names of arguments and values passed: {'q': 't', 'w': None, 'e': 'e'}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 The Thonnu