Python Forum

Full Version: how to write messages from command window to log file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I want to write every this which is showing while running my python script. I use below code, but its not writing q & b values, but they are printing on the command window.

#%%
logfile = open("logfile.log", "a")
logfile.write("hello")
a= 0
b=9
print(a)
print(b)
logfile.close()
print(a, file=logfile)
Or else:
logfile.write(str(a))