Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson12-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
c7f15af0
authored
May 30, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
587a25e4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
3 deletions
__pycache__/diy.cpython-37.pyc
ab.py
diy.py
__pycache__/diy.cpython-37.pyc
0 → 100644
View file @
c7f15af0
File added
ab.py
0 → 100644
View file @
c7f15af0
import
diy
while
True
:
aba
=
input
(
"你想写入还是读取呢?注:写入输入'w'读取输入'r'改输入'g''q'退出"
)
if
aba
==
"w"
:
diy
.
zhuijia
()
if
aba
==
"r"
:
diy
.
duqu
()
if
aba
==
"q"
:
break
if
aba
==
"g"
:
v
=
diy
.
gai
()
diy
.
xie
(
v
)
\ No newline at end of file
diy.py
View file @
c7f15af0
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
a
=
open
(
r"C:\Users\ycl77\Desktop\sfjbnqug.txt"
,
"w"
,
encoding
=
"UTF-8"
)
a
.
write
(
"小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'"
)
a
.
close
()
def
zhuijia
():
while
True
:
yonghu
=
input
(
"用户输入内容"
)
if
yonghu
==
"q"
:
break
else
:
with
open
(
r"C:\Users\ycl77\Desktop\sfjbnqug.txt"
,
"a"
,
encoding
=
"UTF-8"
)
as
a
:
a
.
write
(
yonghu
+
"
\n
"
)
def
duqu
():
with
open
(
r"C:\Users\ycl77\Desktop\sfjbnqug.txt"
,
"r"
,
encoding
=
"UTF-8"
)
as
a
:
zhi
=
a
.
read
()
print
(
zhi
)
def
gai
():
new
=
""
gai_new
=
input
(
"请输入要改的旧值:"
)
new_1
=
input
(
"请输入新的值:"
)
with
open
(
r"C:\Users\ycl77\Desktop\sfjbnqug.txt"
,
"r"
,
encoding
=
"UTF-8"
)
as
a
:
# print(zhi)
for
i
in
a
:
if
gai_new
in
i
:
i
=
i
.
replace
(
gai_new
,
new_1
)
new
+=
i
return
new
def
xie
(
abab
):
with
open
(
r"C:\Users\ycl77\Desktop\sfjbnqug.txt"
,
"w"
,
encoding
=
"UTF-8"
)
as
a
:
a
.
write
(
abab
)
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