Python Forum
python file output to log file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python file output to log file
#5

  1. You have to use the log('Your Message') everywhere, where you want to log. The print_function stays still the print_function and does not change.
  2. You're using Python 2.7, which is deprecated 2020. Upgrade to Python 3.7. In Python 2.7 print is not a function, it's a statement and the parenthesis around the arguments are recognized as a tuple and a tuple has no keyword assignment. If you need to stay with legacy Python, you should use the imports from __future__:
    from __future__ import print_function
    Then you must use everywhere print as a function

The logging module is doing a better job. You've more control about different handlers and formatting.
You could also try https://github.com/Delgan/loguru
The boiler-plate code has been removed :-)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
python file output to log file - by Rsh - Aug-12-2019, 04:15 PM
RE: python file output to log file - by wavic - Aug-12-2019, 07:04 PM
RE: python file output to log file - by DeaD_EyE - Aug-12-2019, 08:48 PM
RE: python file output to log file - by Rsh - Aug-13-2019, 01:17 PM
RE: python file output to log file - by DeaD_EyE - Aug-13-2019, 09:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to remove unwanted images and tables from a Word file using Python? rownong 2 750 Feb-04-2025, 08:30 AM
Last Post: Pedroski55
  Best way to feed python script of a file absolut 6 1,088 Jan-11-2025, 07:03 AM
Last Post: Gribouillis
  Removal of watermark logo pdf file Python druva 0 680 Jan-01-2025, 11:55 AM
Last Post: druva
  How to write variable in a python file then import it in another python file? tatahuft 4 911 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  How to communicate between scripts in python via shared file? daiboonchu 4 1,621 Dec-31-2024, 01:56 PM
Last Post: Pedroski55
  Problems writing a large text file in python Vilius 4 988 Dec-21-2024, 09:20 AM
Last Post: Pedroski55
  How to re-register .py file extension to new moved Python dir (on Windows)? pstein 5 1,272 Nov-06-2024, 03:06 PM
Last Post: DeaD_EyE
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 1,058 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  FileNotFoundError: [Errno 2] No such file or directory although the file exists Arnibandyo 0 907 Aug-12-2024, 09:11 AM
Last Post: Arnibandyo
  To fetch and iterate data from CSV file using python vyom1109 3 1,009 Aug-05-2024, 10:05 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

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