code update

This commit is contained in:
Kristofers Solo 2021-10-11 21:49:27 +03:00
parent ef13ea8498
commit f63623db5c

View File

@ -7,7 +7,7 @@ CHAPTERS = 61
# creates file with chapters and row numbers # creates file with chapters and row numbers
def read_array(document): def read_array(document):
with open(document, encoding='utf-8') as book: with open(document, "r", encoding='utf-8') as book:
lines = [line.strip('\n') for line in book] # removes 'enter' characters lines = [line.strip('\n') for line in book] # removes 'enter' characters
with open('array_output.txt', 'w') as output: with open('array_output.txt', 'w') as output:
for i in range(1, CHAPTERS + 1): for i in range(1, CHAPTERS + 1):
@ -17,7 +17,7 @@ def read_array(document):
# creates file with chapter positions # creates file with chapter positions
def read_string(document): def read_string(document):
with open(document, encoding='utf-8') as book: with open(document, "r", encoding='utf-8') as book:
lines = book.read() lines = book.read()
with open('str_output.txt', 'w') as output: with open('str_output.txt', 'w') as output:
for i in range(1, CHAPTERS + 1): for i in range(1, CHAPTERS + 1):
@ -32,15 +32,12 @@ def read_book(document):
def main(): def main():
try: try:
document = "book.txt" read_book("book.txt")
read_book(document)
except: except:
try: try:
document = "1342-0.txt" read_book("1342-0.txt")
read_book(document)
except: except:
document = input("Ievadiet faila nosaukumu: ") read_book(input("Ievadiet faila nosaukumu: "))
read_book(document)
if __name__ == '__main__': if __name__ == '__main__':