Python Forum
How to assign input file name as logger name
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to assign input file name as logger name
#4
you greatly modified your code after my post, (as seen by clicking 'view edit history' on original post)
so now it looks like my response was entirely out of context!

it looks like inFile is a file pointer, which had to be opened somewhere (nor shown) within the program
wherever that occurs, you need to to capture the 'stem' of the filename, and modify line 24 to read (I am can't show how to do this as you do not show where file was opened):
filename = f"{stem}{datetime.today().strftime('%Y%m%d_%H%M%S')}.txt"

example: (assuming stem was created from inFile file name)

>>> from datetime import datetime
>>> stem = 'ziggy' # extract stem from name of inFile
>>> filename = f"{stem}{datetime.today().strftime('%Y%m%d_%H%M%S')}.txt"
>>> print(filename)
ziggy20200803_102219.txt
>>>
Reply


Messages In This Thread
RE: How to assign input file name as logger name - by Larz60+ - Aug-03-2020, 02:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  logger behaviour setdetnet 1 935 Apr-15-2023, 05:20 AM
Last Post: Gribouillis
  how to write exception error into logger mg24 3 1,042 Nov-15-2022, 04:20 PM
Last Post: insharazzak
  python insert blank line in logger mg24 1 2,995 Nov-02-2022, 08:36 AM
Last Post: snippsat
  python logger help ... save logger into different folder mg24 1 1,606 Oct-25-2022, 03:04 PM
Last Post: snippsat
  Closing logger from other function problem Paqqno 1 1,160 Apr-25-2022, 11:49 AM
Last Post: Gribouillis
  Closing logger to rename directory malcoverc 1 1,266 Apr-19-2022, 07:06 AM
Last Post: Gribouillis
  Reading an Input File DaveG 1 1,293 Mar-27-2022, 02:08 AM
Last Post: deanhystad
  logger option , where is the file? korenron 1 1,840 Apr-25-2021, 01:28 PM
Last Post: snippsat
  Split and sort input file aawaleh 4 3,060 Apr-10-2020, 09:59 PM
Last Post: aawaleh
  User Input and CSV File Davy_Jones_XIV 2 4,881 Mar-24-2020, 08:43 AM
Last Post: Davy_Jones_XIV

Forum Jump:

User Panel Messages

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