Skip to content

Instantly share code, notes, and snippets.

@ohr-emet
Created May 16, 2020 10:32
Show Gist options
  • Save ohr-emet/6cc3481856dea2c6981cbab11c7d542f to your computer and use it in GitHub Desktop.
Save ohr-emet/6cc3481856dea2c6981cbab11c7d542f to your computer and use it in GitHub Desktop.
py4e - Ch 7 Files: Ex1 [convert to upper]
'''Write a program to read through a file and print the contents of the file (line by line) all in upper case. Executing the program will look as follows:
python shout.py
Enter a file name: mbox-short.txt
FROM [email protected] SAT JAN 5 09:14:16 2008
RETURN-PATH: <[email protected]>
RECEIVED: FROM MURDER (MAIL.UMICH.EDU [141.211.14.90])
BY FRANKENSTEIN.MAIL.UMICH.EDU (CYRUS V2.3.8) WITH LMTPA;
SAT, 05 JAN 2008 09:14:16 -0500
'''
fhand = open(r'C:\Users\AT\Desktop\py4e\Projects\Ch 7\mbox-short.txt')
for line in fhand:
ly = line.rstrip()
print(ly.upper())
@ohr-emet
Copy link
Author

  • For those with Windows, you may experience the issue of not being able to load the file. copy the syntax as below and it should work

open(r'C:\Users\AT\Desktop\py4e\Projects\Ch 7\mbox-short.txt')

  • also watch out for the () in ly.upper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment