Created
July 10, 2018 15:08
-
-
Save kieranjol/d2b51f403d9200d884320e8394953c20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # import a bunch of python libraries that we'll need later. | |
| import sys | |
| import os | |
| import re | |
| # This stores a variable called imdb_text which just stores the textfile filename. | |
| imdb_text = sys.argv[1] | |
| # This just stores the new edited sidecat textfile. | |
| new_textfile = imdb_text + '_edited_by_script.txt' | |
| # This will print a statement to the screen. | |
| print('You have chosen %s as your input' % imdb_text) | |
| # This opens up your textfile and reads the lines and stores them as a list. | |
| with open(imdb_text, 'r') as textobject: | |
| lines = textobject.readlines() | |
| # This iterates through each line in the list: | |
| for line in lines: | |
| # This pulls out the bit before the first tab | |
| agent = re.split(r'\t+', line)[0] | |
| # these are the dots | |
| nonsense = re.split(r'\t+', line)[1] | |
| # this pulls out the bit after the last tab | |
| role = re.split(r'\t+', line)[2].rstrip() | |
| with open(new_textfile, 'a') as fo: | |
| fo.write("|%s (%s)\n" % (agent, role)) | |
| print('A new textfile has been created here: %s' % new_textfile) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment