FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Python_Basics/python_programs/file_reading.py at master · learnbyexample/Python_Basics · GitHub
This repository was archived by the owner on Dec 29, 2020. It is now read-only.
learnbyexample
/
Python_Basics
Public archive
Notifications
You must be signed in to change notification settings
Fork
196
Star
614
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Python_Basics
/
python_programs
/
file_reading.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
21 lines (16 loc) · 482 Bytes
Breadcrumbs
Python_Basics
/
python_programs
/
file_reading.py
Copy path
File metadata and controls
21 lines (16 loc) · 482 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/python3
# open file, read line by line and print it
filename
=
'hello_world.py'
f
=
open
(
filename
,
'r'
,
encoding
=
'ascii'
)
print
(
"Contents of "
+
filename
)
print
(
'-'
*
30
)
for
line
in
f
:
print
(
line
,
end
=
''
)
f
.
close
()
# 'with' is a simpler alternative, automatically handles file closing
filename
=
'while_loop.py'
print
(
"
\n
\n
Contents of "
+
filename
)
print
(
'-'
*
30
)
with
open
(
filename
,
'r'
,
encoding
=
'ascii'
)
as
f
:
for
line
in
f
:
print
(
line
,
end
=
''
)
Back
|
FazBrowse Home
|
New Git URL