I would like to write a function in Python that will take arguments just like print
does but instead of printing the strings to stdout, I would like to write the strings formatted into a text file.
How do I define the arguments for such a function arguments to accept the string formatting, I'm wondering?
I am looking for something that would replace
print "Test"
with
MyLog "Test"
but the % rguments should also be supported. So far I have only come up with this:
def logger(txt):
fh = open (LOGFILE, "a") #Get handle in append mode
fh.write(txt)
fh.close()
print txt
return True
which works fine for a simple string but i don't think it'll take the % arguments nor will I be able to call it like logger "TEST"