Python Forum
Trying to make column based file from text file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to make column based file from text file
#4
Realized I wasn't opening file thought maybe that was cause of it...but still didn't work

rows = []
mode = 'nowhere'
with open('PYTHON GDL Resources.txt', 'r') as file:
    for line in file:
        if line:
            if mode == 'nowhere':
                mode = 'header'
                header_data = []  # resets the header info for each new section
            elif 'Access' in line:
                if 'No users with' in line:
                    continue
                mode == 'access'
                if mode == 'header':
                # pull out header information and put it into header_data
                elif mode == 'Access':
                    access_type, users = line.split(':') # everything after the colon
                    for user in users.split(','):
                    rows.append(header_data + [user.strip(), access_type.strip()])
        else:
        mode = 'nowhere'   # start looking for new section
Reply


Messages In This Thread
RE: Trying to make column based file from text file - by scor1pion - Jul-16-2019, 12:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 13 29,219 May-20-2025, 12:26 PM
Last Post: hanmen9527
  How to write variable in a python file then import it in another python file? tatahuft 4 1,147 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  Problems writing a large text file in python Vilius 4 1,216 Dec-21-2024, 09:20 AM
Last Post: Pedroski55
  How to make it so whatever I input into a script gets outputted on a different file spermatozwario 4 1,350 Nov-24-2024, 12:58 PM
Last Post: deanhystad
  Get an FFMpeg pass to subprocess.PIPE to treat list as text file? haihal 2 1,242 Nov-21-2024, 11:48 PM
Last Post: haihal
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 1,234 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  FileNotFoundError: [Errno 2] No such file or directory although the file exists Arnibandyo 0 1,336 Aug-12-2024, 09:11 AM
Last Post: Arnibandyo
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 7,378 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  Reading an ASCII text file and parsing data... oradba4u 2 1,612 Jun-08-2024, 12:41 AM
Last Post: oradba4u
  very newbie problem on text file zapad 2 1,203 Apr-12-2024, 06:50 PM
Last Post: zapad

Forum Jump:

User Panel Messages

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