mirror of
https://github.com/kristoferssolo/School.git
synced 2025-10-21 20:10:38 +00:00
added try|except
This commit is contained in:
parent
a398800d86
commit
ef13ea8498
@ -1,9 +1,11 @@
|
||||
# Author - Kristiāns Francis Cagulis
|
||||
# Date - 06.10.2021
|
||||
import re
|
||||
|
||||
CHAPTERS = 61
|
||||
|
||||
|
||||
# creates file with chapters and row numbers
|
||||
def read_array(document):
|
||||
with open(document, encoding='utf-8') as book:
|
||||
lines = [line.strip('\n') for line in book] # removes 'enter' characters
|
||||
@ -13,8 +15,8 @@ def read_array(document):
|
||||
output.write(f"Line {line} - Chapter {i}\n") # writes line in file
|
||||
|
||||
|
||||
# creates file with chapter positions
|
||||
def read_string(document):
|
||||
import re
|
||||
with open(document, encoding='utf-8') as book:
|
||||
lines = book.read()
|
||||
with open('str_output.txt', 'w') as output:
|
||||
@ -23,11 +25,23 @@ def read_string(document):
|
||||
output.write(f"Position {position.start()} - Chapter {i}\n") # writes position in file
|
||||
|
||||
|
||||
def main():
|
||||
document = input("Ievadiet faila nosaukumu: ")
|
||||
def read_book(document):
|
||||
read_array(document)
|
||||
read_string(document)
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
document = "book.txt"
|
||||
read_book(document)
|
||||
except:
|
||||
try:
|
||||
document = "1342-0.txt"
|
||||
read_book(document)
|
||||
except:
|
||||
document = input("Ievadiet faila nosaukumu: ")
|
||||
read_book(document)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Reference in New Issue
Block a user