Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson12-2
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
cd496cab
authored
Oct 30, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
59f687ca
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
0 deletions
1.py
test.txt
wanmei.txt
1.py
0 → 100644
View file @
cd496cab
new_data
=
''
#新建变量
with
open
(
'wanmei.txt'
,
'w'
,
encoding
=
'utf-8'
)
as
file
:
#写入文件
a
=
[
'小兰:12本
\n
'
,
'小强:15本
\n
'
,
'豆豆:30本
\n
'
]
#写入序列字符串
file
.
writelines
(
a
)
with
open
(
'wanmei.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
#读取文件
for
data
in
file
:
#遍历文件内容
if
'小兰:12本'
in
data
:
data
=
data
.
replace
(
'小兰:12本'
,
'小兰:13本'
)
#修改数据内容
new_data
+=
data
#保存新文件
with
open
(
'wanmei.txt'
,
'w'
,
encoding
=
'utf-8'
)
as
file
:
#写入新文件
file
.
write
(
new_data
)
test.txt
0 → 100644
View file @
cd496cab
wanmei.txt
0 → 100644
View file @
cd496cab
小兰:13本
小强:15本
豆豆:30本
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