Skip to content

Instantly share code, notes, and snippets.

@martin-martin
Created July 31, 2020 08:46
Show Gist options
  • Save martin-martin/209e9958e25d27c4182fb32ce65ce3ed to your computer and use it in GitHub Desktop.
Save martin-martin/209e9958e25d27c4182fb32ce65ce3ed to your computer and use it in GitHub Desktop.
Reading book files and printing the first character
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