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
#3
Hi Ichabod, Thank you for your reply.

I'm sure its just my lack of understanding as this is all very new to me still. I have been taking classes through the datacamp site...still have a couple of courses to go. I haven't come across the mode function yet. Any recommendations for a more detailed self taught course?

When I tried to run the script I got this

File "C:/Users/Keith/Desktop/PY/venv/test.py", line 16
elif mode == 'Access':
^
IndentationError: expected an indented block


file = 'PYTHON GDL Resources.txt'

rows = []
mode = 'nowhere'
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-15-2019, 10:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 931 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  Reading an ASCII text file and parsing data... oradba4u 2 285 Jun-08-2024, 12:41 AM
Last Post: oradba4u
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 1,619 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  very newbie problem on text file zapad 2 456 Apr-12-2024, 06:50 PM
Last Post: zapad
  Copy Paste excel files based on the first letters of the file name Viento 2 636 Feb-07-2024, 12:24 PM
Last Post: Viento
  Help copying a column from a csv to another file with some extras g0nz0uk 3 658 Feb-01-2024, 03:12 PM
Last Post: DeaD_EyE
  file open "file not found error" shanoger 8 1,662 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Replace a text/word in docx file using Python Devan 4 4,660 Oct-17-2023, 06:03 PM
Last Post: Devan
  Need to replace a string with a file (HTML file) tester_V 1 951 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  Color a table cell based on specific text Creepy 11 2,626 Jul-27-2023, 02:48 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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