File tree Expand file tree Collapse file tree 2 files changed +3
-16
lines changed Expand file tree Collapse file tree 2 files changed +3
-16
lines changed Original file line number Diff line number Diff line change 1
1
Alas, poor Yorick! I knew him, Horatio: a fellow
2
-
3
2
of infinite jest, of most excellent fancy: he hath
4
-
5
3
borne me on his back a thousand times; and now, how
6
-
7
4
abhorred in my imagination it is! my gorge rims at
8
-
9
5
it. Here hung those lips that I have kissed I know
10
-
11
6
not how oft. Where be your gibes now? your
12
-
13
7
gambols? your songs? your flashes of merriment,
14
-
15
8
that were wont to set the table on a roar? Not one
16
-
17
9
now, to mock your own grinning? quite chap-fallen?
18
-
19
10
Now get you to my lady’s chamber, and tell her, let
20
-
21
11
her paint an inch thick, to this favour she must
22
-
23
12
come; make her laugh at that.
Original file line number Diff line number Diff line change 3
3
os .chdir (r'P:\Python Projects\Python-Notes\files' ) # set's the working directory for the python script:
4
4
# Allows us to open File.txt without having to type the full file path in the open() method
5
5
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
7
7
# and assign it to the open() method, with the file name included in the parenthesis.
8
8
# This doesn't read the file into the program, it more or less "imports" it and allows you to call it later
9
9
# much like importing an additional python module
18
18
19
19
# The print() function in python automatically adds a new line after it reads the line from a txt file
20
20
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=
22
22
count = 0
23
- for i in ofile :
23
+ for i in rfile :
24
24
count = count + 1
25
-
26
- print ("there are " , count , " in this excerpt" )
You can’t perform that action at this time.
0 commit comments