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
#5
I did not open the file anywhere, I directly defined it in line 22. DO I need to modify the code? can you please suggest whre (and how) to change it. Below is my complete code.

import logging
import pandas as pd
from datetime import datetime
   
class MyData:  
    def __init__(self):  
        self.mode = None
    def read_data(self, inFile, colNames, mode):
        try:
            df_tmp = pd.read_csv(inFile)
            print(df_tmp.head(2))
            logging.debug("Read data successfully")
            data.mod_data()
        except OSError as e:
            logging.debug("File read fail check fail reason below")
            logging.debug(e.errno)
    def mod_data(self):
 
        print("New Df.......")
        print(self.df)
   
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s.%(msecs)04d:%(levelname)s: %(message)s',
                    filename=('mylog'+datetime.today().strftime('%Y%m%d_%H%M%S')+".txt"),
                    filemode='w',datefmt='%Y-%m-%d %H:%M:%S')
 
logging.debug("Hello new log")
logging.debug("Initialize file read...")
   
data = MyData()
data.read_data(csvfile = r'HATY.csv', cols = 'col1', opmode = 'NOM')
Reply


Messages In This Thread
RE: How to assign input file name as logger name - by Mekala - Aug-04-2020, 12:16 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,882 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