Advertisement
Guest User

question

a guest
Jun 18th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. """
  2. I have data in file "wesele.txt" that I proceeded to format like:
  3. _________________________________
  4.  
  5. CZEPIEC
  6.  
  7. Cóz tam, panie, w polityce?
  8.                                         _____ <- shows beginnig and end
  9. Chińcyki trzymają się mocno!?
  10.  
  11. DZIENNIKARZ
  12.  
  13. A, mój miły gospodarzu,
  14.  
  15. mam przez cały dzień dosyć Chińczyków.
  16. _____________________________________
  17.  
  18. and I want it to be like:
  19. _____________________________________
  20. CZEPIEC:
  21. Cóz tam, panie, w polityce?
  22. Chińcyki trzymają się mocno!?
  23.  
  24. DZIENNIKARZ:
  25. A, mój miły gospodarzu,
  26. mam przez cały dzień dosyć Chińczyków
  27. _______________________________________
  28. With " : " after lines that says who is talking
  29. and only one space after the text
  30. """
  31.  
  32. import os
  33. # go to catalog with text
  34. os.chdir('/home/patryk/PycharmProjects/zmiana ksiazki')
  35. # open wesele and read all lines (tekst means text)
  36. with open('wesele.txt', 'r') as file:
  37.     tekst = file.readlines()
  38. new_text = []   # needed text
  39. for line in tekst:
  40.     # checks A-Z
  41.     if ord(line[0]) in [x for x in range(65,91)]:
  42.         line = line + ":"
  43.     elif ord(line[0]) == "\": # <- HERE I get sth strange as
  44.                               # if I couldnt use brackets
  45.                               # like "" for \ in lines with only "\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement