#Isaiah Hendry
#Oct 28 2021
#U2M4A4.1
# i am playing with file import
# [ ] review and run example
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/poem1.txt -o poem1.txt
# [ ]Run to open the file in memory as poem_file
poem_file = open('poem1.txt', 'r')
# [ ] run and review code to test if open worked
# should display name='poem1.txt' and no errors
poem_file
# [ ] import cities.txt
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/cities -o cities.txt
# [ ] open cities.txt as cities_file
# [ ] test cities.txt was opened
cities_file = open('poem1.txt', 'r')
cities_file
# [ ] review and run example
poem_contents = poem_file.read()
# [ ] review and run example
# shows the file as a string with formatting characters such as "\n", output should be non-blank
poem_contents
# [ ] review and run example
# since .read() loaded the file as a string it can be printed
print(poem_contents)
# [ ] after import and open of cities.txt in task 1
# [ ] read cities_file as cities
# [ ] display the string: cities
https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/cities
# [ ] print the string: cities
print(cities)
# [ ] review and run example to read poem1.txt 10 characters at a time
poem_file = open('poem1.txt', 'r')
poem_10char = poem_file.read(10)
print(poem_10char)
poem_10char
# [ ] review and run example, + 10 more characters
# reads and displays without storing in a variable
poem_file.read(10)
# [ ] review and run example, + 10 more characters
# reads and stores in variable poem_parts
poem_parts = poem_file.read(10)
print(poem_parts)
# [ ] REPEATEDLY RUN this cell, + 5 more characters each time run are appended using string addition
# [ ] consider why no additional text displays after multiple runs
poem_parts += poem_file.read(5)
print(poem_parts)
# [ ] digits of pi
# 1. import digits_of_pi.txt
# [ ] digits of pi
# 2. open as digits_of_pi_text
# 3. read() 4 char of digits_of_pi_text to pi_digits variable
# 4. print pi_digits
# [ ] digits of pi
# 5. add to pi_digits string with string addition
# a. add next 4 characters from digits_of_pi obtained from read()
# b. run the cell multiple times to get more digits of *pi*
# [ ] review and run example
poem_file = open('poem1.txt', 'r')
poem_part = poem_file.read(15).upper()
print(poem_part)
# [ ] review and run example
poem_part = poem_file.read(6).title()
print(poem_part)
# [ ] review and run example
poem_part = poem_file.read(6)
print(poem_part)
print(poem_part.isalpha(), "isalpha() because of `\\n`")
poem_part
# [ ] review and run example
poem_file = open('poem1.txt', 'r')
poem_text = poem_file.read()
print(poem_text[8:26])
# [ ] complete the task