Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson13-1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d0d81e42
authored
Sep 11, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
5ec53ebb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
diy.py
diy.py
View file @
d0d81e42
#打开文件的两种方法
#方法1
with
open
(
r'C:\Users\HP\Desktop\bell\文件读写\book.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
#方法二
file
=
open
(
r'C:\Users\HP\Desktop\bell\文件读写\book.txt'
,
'r'
,
encoding
=
'utf-8'
)
#file.close()
#在第一个的基础上,修改
with
open
(
r'C:\Users\HP\Desktop\bell\文件读写\book.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
a
=
file
.
readlines
()
for
i
in
a
:
#用for...in...将每一行的数据遍历一边
print
(
i
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment