Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- I have data in file "wesele.txt" that I proceeded to format like:
- _________________________________
- CZEPIEC
- Cóz tam, panie, w polityce?
- _____ <- shows beginnig and end
- Chińcyki trzymają się mocno!?
- DZIENNIKARZ
- A, mój miły gospodarzu,
- mam przez cały dzień dosyć Chińczyków.
- _____________________________________
- and I want it to be like:
- _____________________________________
- CZEPIEC:
- Cóz tam, panie, w polityce?
- Chińcyki trzymają się mocno!?
- DZIENNIKARZ:
- A, mój miły gospodarzu,
- mam przez cały dzień dosyć Chińczyków
- _______________________________________
- With " : " after lines that says who is talking
- and only one space after the text
- """
- import os
- # go to catalog with text
- os.chdir('/home/patryk/PycharmProjects/zmiana ksiazki')
- # open wesele and read all lines (tekst means text)
- with open('wesele.txt', 'r') as file:
- tekst = file.readlines()
- new_text = [] # needed text
- for line in tekst:
- # checks A-Z
- if ord(line[0]) in [x for x in range(65,91)]:
- line = line + ":"
- elif ord(line[0]) == "\": # <- HERE I get sth strange as
- # if I couldnt use brackets
- # like "" for \ in lines with only "\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement