Python Forum
how to write messages from command window to log file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to write messages from command window to log file
#1
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()
Reply
#2
print(a, file=logfile)
Or else:
logfile.write(str(a))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Control of the number of daemon error messages to the file MarPan 3 87 Mar-25-2026, 11:00 AM
Last Post: DeaD_EyE
  If I open a file write or append, is the file loaded into RAM? Pedroski55 11 1,118 Jan-14-2026, 07:49 AM
Last Post: Pedroski55
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 7,273 Dec-16-2025, 05:29 PM
Last Post: zodazy
  how to write/overwrite data in a txt. file according to inp Quinn 2 1,587 Aug-12-2025, 04:20 PM
Last Post: Quinn
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 13 36,670 May-20-2025, 12:26 PM
Last Post: hanmen9527
  How to write variable in a python file then import it in another python file? tatahuft 4 2,253 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  How to run shell command, capture the output, then write it into textfile? tatahuft 4 1,828 Dec-20-2024, 02:13 PM
Last Post: Axel_Erfurt
  [SOLVED] [Linux] Write file and change owner? Winfried 6 3,193 Oct-17-2024, 01:15 AM
Last Post: Winfried
  no debug messages going into log file robertkwild 0 957 Jul-09-2024, 05:30 PM
Last Post: robertkwild
  What does .flush do? How can I change this to write to the file? Pedroski55 3 2,259 Apr-22-2024, 01:15 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020