Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. import csv
  2. import time
  3. import re
  4. def find_lines():
  5.         for x in range(len(randySeasonOne[speaker])):
  6.                 print(randySeasonOne[speaker][x])
  7.  
  8.  
  9. filename = ("/code/SouthParkData/Season-1.csv")
  10. speaker = input("Character Selection>>").strip()
  11. season = input("Season Selection>>").strip()
  12. episode = input("Episode selection>>").strip()
  13. print("-"*25)
  14. print("Here are all the lines from ", speaker)
  15. time.sleep(2)
  16. with open(filename, 'r') as file:
  17.         reader = csv.DictReader(file, fieldnames=['season', 'episode', 'speaker', 'line'])
  18.         lines = {speaker:[]}
  19.         for row in reader:
  20.                 if row['speaker'] == speaker and row['season'] == season and row['episode'] == episode:
  21.                         print(row['speaker'])
  22.                         #for x in range(len(lines[speaker])-1):
  23.                                 #line =  re.sub(r'\A\W', ' ', row['line'])
  24.                                 #lines[speaker].append(line)
  25.                                 #print(line)
  26.                                 #time.sleep(.125)
  27.                         print(row['line']) #see what original value is.. thought maybe there was a newline char at end
  28.                         line = re.sub(r'\A\W', ' ', row['line'])
  29.                         line = re.sub(r'\Z\W', ' ', line)
  30.                         print(line) #should be completely sanitized, but still shows the ending parenthesis
  31.  
  32.  
  33. Input :
  34. Character Selection> Kenny
  35. Season selection> 1
  36. Episode selection> 9
  37.  
  38. Kenny
  39. Line goes here)  <--- ending parenthesis im trying to remove with re.sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement