Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XML log file --> CSV
#2
Your output doesn't make sense if you're generating csv.

That said, string concatenation inside a loop is normally frowned upon for performance reasons, and lists are suggested instead.  In your case, you also get the added benefit of removing the trailing pipe that way.
Here's some completely untested code, which should be pretty close to right:
with open(inFile) as f:
    with open(outFile, "w") as fout:
        parts = [ ]
        for line in f:
            line = line.strip()
            if line:
                parts.append(line)
            else:
                print("|".join(parts), file=fout)
                parts = [ ]
        if parts:
            print("|".join(parts), file=fout)
Reply


Messages In This Thread
XML log file --> CSV - by olivercfc - Oct-13-2017, 08:23 PM
RE: XML log file --> CSV - by nilamo - Oct-16-2017, 09:13 PM

Forum Jump:

User Panel Messages

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