Skip to content

Commit 1a60a23

Browse files
committed
updated files
1 parent 9189b6c commit 1a60a23

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

Files/File.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
Alas, poor Yorick! I knew him, Horatio: a fellow
2-
32
of infinite jest, of most excellent fancy: he hath
4-
53
borne me on his back a thousand times; and now, how
6-
74
abhorred in my imagination it is! my gorge rims at
8-
95
it. Here hung those lips that I have kissed I know
10-
116
not how oft. Where be your gibes now? your
12-
137
gambols? your songs? your flashes of merriment,
14-
158
that were wont to set the table on a roar? Not one
16-
179
now, to mock your own grinning? quite chap-fallen?
18-
1910
Now get you to my lady’s chamber, and tell her, let
20-
2111
her paint an inch thick, to this favour she must
22-
2312
come; make her laugh at that.

Files/files.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
os.chdir(r'P:\Python Projects\Python-Notes\files') # set's the working directory for the python script:
44
# Allows us to open File.txt without having to type the full file path in the open() method
55

6-
ofile = open("File.txt") # To enable users to gain access to a file, we need to instantiate a variable
6+
ofile = open("File.txt", 'r') # To enable users to gain access to a file, we need to instantiate a variable: the 'r' actually sets the file to read mode
77
# and assign it to the open() method, with the file name included in the parenthesis.
88
# This doesn't read the file into the program, it more or less "imports" it and allows you to call it later
99
# much like importing an additional python module
@@ -18,9 +18,7 @@
1818

1919
# The print() function in python automatically adds a new line after it reads the line from a txt file
2020

21-
rfile = ofile.read() #reads a file into memory
21+
rfile = ofile.read() #reads entire file into memory and assigns it to a string variable=
2222
count = 0
23-
for i in ofile :
23+
for i in rfile :
2424
count = count + 1
25-
26-
print("there are ", count, " in this excerpt")

0 commit comments

Comments
 (0)