Tested in Spyder 3.3.3 (for Python 3.7).
users.txt
Jackson, Eddie
Bach, Joseph
Johnson, Larry
Lowe, Daniel
Denning, Jeffrey
users.py
# MrNetTek # eddiejackson.net/blog # 9/7/2020 # free for public use # free to claim as your own from os import system system('cls') file1 = open("users.txt", "r") print("\nWHOLE TEXT FILE") print("------------------") print(file1.read()) file1.close() print("\n\nLINE BY LINE") print("------------------") file2 = open('users.txt', 'r') Lines = file2.readlines() count = 1 for line in Lines: print("Line{}: {}".format(count, line.strip())) count += 1 file2.close() print("\n\nLINE BY LINE, REMOVE COMMA") print("------------------") file3 = open('users.txt', 'r') Lines = file3.readlines() count = 1 for line in Lines: line = line.replace(',', '') print("Line{}: {}".format(count, line.strip())) count += 1 file3.close() print("\n\nLINE BY LINE, REMOVE COMMA, SPLIT, FIRST LAST NAME") print("------------------") file4 = open('users.txt', 'r') Lines = file4.readlines() count = 1 for line in Lines: line = line.replace(',', '') line = line.replace('\n', '') data = line.split(" ") print("Line{}: {}".format(count,data[1] + " " + data[0])) count += 1 file4.close() #simple wait #input("\nPress any key to continue...") #disconnect from kernel #key = input('\nPress any key to continue...') #quit()
Output
WHOLE TEXT FILE
——————
Jackson, Eddie
Bach, Joseph
Johnson, Larry
Lowe, Daniel
Denning, Jeffrey
LINE BY LINE
——————
Line1: Jackson, Eddie
Line2: Bach, Joseph
Line3: Johnson, Larry
Line4: Lowe, Daniel
Line5: Denning, Jeffrey
LINE BY LINE, REMOVE COMMA
——————
Line1: Jackson Eddie
Line2: Bach Joseph
Line3: Johnson Larry
Line4: Lowe Daniel
Line5: Denning Jeffrey
LINE BY LINE, REMOVE COMMA, SPLIT, FIRST LAST NAME
——————
Line1: Eddie Jackson
Line2: Joseph Bach
Line3: Larry Johnson
Line4: Daniel Lowe
Line5: Jeffrey Denning