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
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 12 28,153 Feb-13-2025, 04:48 AM
Last Post: tomhansky
  How to write variable in a python file then import it in another python file? tatahuft 4 955 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  How to run shell command, capture the output, then write it into textfile? tatahuft 4 976 Dec-20-2024, 02:13 PM
Last Post: Axel_Erfurt
  [SOLVED] [Linux] Write file and change owner? Winfried 6 1,567 Oct-17-2024, 01:15 AM
Last Post: Winfried
  no debug messages going into log file robertkwild 0 547 Jul-09-2024, 05:30 PM
Last Post: robertkwild
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 4,384 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  What does .flush do? How can I change this to write to the file? Pedroski55 3 1,357 Apr-22-2024, 01:15 PM
Last Post: snippsat
  Last record in file doesn't write to newline gonksoup 3 1,618 Jan-22-2024, 12:56 PM
Last Post: deanhystad
  write to csv file problem jacksfrustration 11 5,237 Nov-09-2023, 01:56 PM
Last Post: deanhystad
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 3,901 Nov-09-2023, 10:56 AM
Last Post: mg24

Forum Jump:

User Panel Messages

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