Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not sure where to start?
#1


Hey guys,

Sorry if yet another noob question - hoping you are all kind enough to help out / point me in the right direction because I'm not even sure where to start with what I'm trying to do.

My script / program is downloading a bunch of csv files off a ftp server and I'm using sqlldr via a Popen process to import them into an oracle DB. This is all working perfectly along with some other validation checks after the load, and now for the part where I'm stuck Smile

I have the code below which is running without an issue and is giving me the expected results when executed with print statements.

import linecache
import os

ctl_log_dir = "log_directory"

for file in os.listdir(ctl_log_dir):
    print("Table import results for " + file[:-8] + ": ")
    find_lines = ['Total logical records read:','Total logical records rejected:','Total logical records skipped:','Total logical records discarded:','Rows successfully loaded.']
    with open(ctl_log_dir + file) as f:
        for i, line in enumerate(f, 1):
            for find in find_lines:
                if find in line:
                    print(linecache.getline(ctl_log_dir + file, i).strip())
The output of the print statements is:

Output:
Table import results for TABLENAME1: 703 Rows successfully loaded. Total logical records skipped: 0 Total logical records read: 704 Total logical records rejected: 1 Total logical records discarded: 0 Table import results for TABLENAME2: 17973 Rows successfully loaded. Total logical records skipped: 0 Total logical records read: 17974 Total logical records rejected: 1 Total logical records discarded: 0 Table import results for TABLENAME3: 1151 Rows successfully loaded. Total logical records skipped: 0 Total logical records read: 1152 Total logical records rejected: 1 Total logical records discarded: 0 Table import results for TABLENAME4: 4301 Rows successfully loaded. Total logical records skipped: 0 Total logical records read: 4302 Total logical records rejected: 1 Total logical records discarded: 0 Table import results for TABLENAME5: 5704 Rows successfully loaded. Total logical records skipped: 0 Total logical records read: 5705 Total logical records rejected: 1 Total logical records discarded: 0 Table import results for TABLENAME6: 57 Rows successfully loaded. Total logical records skipped: 0 Total logical records read: 58 Total logical records rejected: 1 Total logical records discarded: 0 Table import results for TABLENAME7: 57 Rows successfully loaded. Total logical records skipped: 0 Total logical records read: 58 Total logical records rejected: 1 Total logical records discarded: 0 Table import results for TABLENAME8: 51 Rows successfully loaded. Total logical records skipped: 0 Total logical records read: 52 Total logical records rejected: 1 Total logical records discarded: 0 Table import results for TABLENAME9: 11094 Rows successfully loaded. Total logical records skipped: 0 Total logical records read: 11095 Total logical records rejected: 1 Total logical records discarded: 0 Table import results for TABLENAME10: 151 Rows successfully loaded. Total logical records skipped: 0 Total logical records read: 152 Total logical records rejected: 1 Total logical records discarded: 0 Table import results for TABLENAME11: 161 Rows successfully loaded. Total logical records skipped: 0 Total logical records read: 162 Total logical records rejected: 1 Total logical records discarded: 0
What I'm wanting to do with this output is either:
1. Get it all into 1 long sting OR
2. Get 1 string for each table (eg Table import results for TABLENAME1: + the 5 lines below it)

I thought that I may be able to just concatenate it all into 1 string or a string for each table? But I wasn't to sure what the best way to approach it would be...

Any help will be greatly appreciated!
Reply


Messages In This Thread
Not sure where to start? - by torz - Dec-15-2017, 11:48 AM
RE: Not sure where to start? - by Mekire - Dec-15-2017, 12:09 PM
RE: Not sure where to start? - by torz - Dec-15-2017, 12:31 PM
RE: Not sure where to start? - by Mekire - Dec-15-2017, 12:40 PM
RE: Not sure where to start? - by torz - Dec-15-2017, 02:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  What's the difference b/w assigning start=None and start=" " Madara 1 2,401 Aug-06-2018, 08:23 AM
Last Post: buran

Forum Jump:

User Panel Messages

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