Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 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(lines[speaker][x])
  26.                                 time.sleep(.125)
  27.  
  28. ----------------------------------------------------------------------------Ouput
  29. Character Selection>>Kenny
  30. Season Selection>>1
  31. Episode selection>>9
  32. -------------------------
  33. Here are all the lines from  Kenny
  34. Kenny
  35. Kenny
  36. Kenny
  37. Kenny
  38. Kenny
  39. Kenny
  40. Kenny
  41.  
  42. --------------------------------------------------------Expected Ouput
  43. Kenny
  44. First line that has been sanitized with re.sub
  45. Kenny
  46. Second line, also sanitized
  47. Kenny
  48. Third line, sanitized
  49. etc..
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement