1. Print them to screen
Man = []other = []try: data = open (' sketch.txt ') for each_line in data: try: (role, line_spoken) = Each_li Ne.split (': ', 1) Line_spoken=line_spoken.strip () if role== ' man ': man.append (line_spoken) elif role = = ' Other mans ': other.append (line_spoken) except ValueError: pass data.close () except IOError : print (' The Datafiel is missing! ') Print (' printing=====man===list======= ', mans) print (' printing=====other===list===== ', other)
2. Save the data to Man_data.txt and Other_data.txt
Man = []other = []try: data = open (' sketch.txt ') for each_line in data: try: (role, line_spoken) = Each_li Ne.split (': ', 1) Line_spoken=line_spoken.strip () if role== ' man ': man.append (line_spoken) elif role = = ' Other mans ': other.append (line_spoken) except ValueError: pass data.close () except IOError : print (' The Datafiel is missing! ') Try: man_out = open ("Man_data.txt", "W") other_out = open (' Other_data.txt ', ' a ') print (' Here is data From list ', Man,file=man_out] print (' Save man file to Man_data.txt ') print (' Here's data from list ', Other,file =other_out) print (' Save other file to Other_data.txt ') man_out.close () other_out.close () except IOError: print (' Data file is not exist ')
Python Save data to File