Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unable to write to log file
I try to run read_data function from main, but although it read data, but not writing to log file.

import logging
from datetime import datetime
import pandas as pd
from read_data import data
import os
import sys
import glob

working_dir = sys.argv[0].rpartition("/")[0]
inpath = 'D:\PythonCodes\inputmultifiles'
outpath = 'D:\PythonCodes'
pattern = "*.csv"
def main(inpath,outpath):
    if __name__ == '__main__':
        print("File path",inpath)
        flist =[]
        for f in (glob.glob(pattern)):
        eqp_list = sorted(set(flist))
        print("The eqplist",eqp_list)
    for fname in eqp_list:
        print("infiles path",inpath)

        fname= fname+ "_SR.csv"
        data.read_data(inpath =inpath,inFile = fname, colNames ='col1', mode = 'NOM', delimiter = ",")

import pandas as pd
import logging
import os
import sys
from datetime import datetime

class MyData:  
    def __init__(self):  
        self.mode = None
    def read_data(self, inpath,inFile, colNames, mode, delimiter):
        self.infile = inFile
        print("The infile name",inFile)
        print("The inpath name",inpath)
        self.logname = inFile.split('.csv')[0]        
        %(message)s',filename=(self.logname +'%Y%m%d_%H%M%S%f')+".txt"),
                    filemode='w+',datefmt='%Y-%m-%d %H:%M:%S') 

        logging.debug("Hello new log")
        logging.debug("Initialize file read...")
            self.df = pd.read_csv(inFile)
            output_file = os.path.join(inpath,inFile)
            logging.debug("Read data successfully")
            print("Read data successfully")
        except OSError as e:
            logging.debug("File read fail check fail reason below")

data = MyData()
my csv:


Name  age  eID
AA    23   522
SSG   45   125
AGB    7   4152


Name  age  eID
AK    23   545
BJK   45   895
FGGB  7    202
Quote:I wiant to write log file for each loop separatly.
please elaborate on 'each loop'
I want to write log file for each loop separatly.--> not necesssary. But now it is not even writing any log file.

Possibly Related Threads…
Thread Author Replies Views Last Post
  write mariadb table rows query to each file? shams 1 277 Feb-02-2021, 04:10 PM
Last Post: buran
  Read/Write binary file deanhystad 3 413 Feb-01-2021, 10:29 AM
Last Post: Larz60+
  Running A Parser In VSCode - And Write The Results Into A Csv-File apollo 5 636 Jan-14-2021, 08:58 PM
Last Post: snippsat
  Unable to capture all images of a multipage TIFF file in a merge bendersbender 0 296 Nov-19-2020, 03:09 PM
Last Post: bendersbender
  How do I write a single 8-bit byte to a file? MysticLord 2 641 Sep-03-2020, 12:27 PM
Last Post: MysticLord
  Unable to Validate csv blanck data and write in csv prashant18 0 452 Jul-25-2020, 12:08 PM
Last Post: prashant18
  List Won't Write in Text File IILawrenceII 4 640 Jul-17-2020, 11:16 PM
Last Post: j.crater
  Process Data from one csv file and write to another CSV file specific column ajin9581 1 610 Jun-17-2020, 06:00 PM
Last Post: buran
  Write SQLite query result to file hjk6734 1 611 May-27-2020, 12:17 PM
Last Post: menator01
  Append JSON's and write to file faqsap 4 971 May-15-2020, 04:20 PM
Last Post: faqsap

Forum Jump:

User Panel Messages

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