Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson11_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
91110981
authored
Mar 07, 2025
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
024fb164
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
9 deletions
001.py
func.py
lsit.txt
001.py
0 → 100644
View file @
91110981
f
=
open
(
r"C:\Users\Administrator\Desktop\text.txt"
,
"w"
,
encoding
=
"utf-8"
)
f
.
write
(
"小兰:12本,
\n
小强:10本"
)
#上面是写入模式
f
.
close
()
with
open
(
r"C:\Users\Administrator\Desktop\text.txt"
,
"a"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
"俞老师:30本"
)
# a 是追加模式
new_data
=
""
with
open
(
r"C:\Users\Administrator\Desktop\text.txt"
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
a
=
f
.
readlines
()
# r读取模式
# print(a)
for
data
in
a
:
# print(data)
if
"小兰:12本"
in
data
:
print
(
"数据在里面"
)
data
=
data
.
replace
(
"小兰:12本"
,
"小兰:52本"
)
new_data
=
new_data
+
data
print
(
new_data
)
with
open
(
r"C:\Users\Administrator\Desktop\text.txt"
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
new_data
)
\ No newline at end of file
func.py
View file @
91110981
total
=
[]
a
=
open
(
r"C:\Users\Administrator\Desktop\名单.txt"
,
"w"
,
encoding
=
'utf-8'
)
while
True
:
a
.
write
(
"nihao
\n
abc"
)
unit
=
input
(
"请输入:"
)
a
.
close
()
if
unit
==
'q'
:
\ No newline at end of file
break
else
:
total
.
append
(
unit
)
print
(
total
)
\ No newline at end of file
lsit.txt
0 → 100644
View file @
91110981
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