I saw the following SO posts on variable arguments in Python:
What does ** (double star) and * (star) do for parameters?
function call with named/unnamed and variable arguments in python
Can a variable number of arguments be passed to a function?
None of them answered my question. So, here it goes:
I would like to define couple of functions:
def LogError(log_file, *args):
print("USER ERROR:", ***NOT SURE ABOUT THIS PART***, file=log_file)
def LogWarning(log_file, *args):
print("USER WARNING:", ***NOT SURE ABOUT THIS PART***, file=log_file)
I want to call them using:
error_file = open("somefile")
LogError(error_file, "Unable to find", username, "in the database.")
warning_file = open("somefile")
LogWarning(warning_file, arg1, arg2, arg3)
I want the call to LogError
to be the equivalent of
print("USER ERROR:", "Unable to find", username, "in the database.", file=error_file)
and I want the call to LogWarning
to be the equivalent of
print("USER WARNING:", arg1, arg2, arg3, file=warning_file)
What's the best way to accomplish that?