Created
July 31, 2020 08:46
-
-
Save martin-martin/209e9958e25d27c4182fb32ce65ce3ed to your computer and use it in GitHub Desktop.
Reading book files and printing the first character
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
warpeace=[] | |
with open ("books/war_and_peace.txt", "r") as store: | |
warpeace.append(store.readlines()) | |
print(warpeace[0]) | |
with open ("books/crime_and_punishment.txt", "w") as overwrite: | |
overwrite.write("") | |
for book in os.listdir(r"books/"): | |
with open (f"books/{book}", "r") as x: | |
first_line=x.readline() | |
print(first_line[:2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment