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
7e1aeb4c
authored
Nov 17, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
d6cd5b97
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
1.py
diy.py
1.py
0 → 100644
View file @
7e1aeb4c
open
函数的格式
文件名
=
open
(
r
‘地址’,‘模式’,
encoding
=
"编码"
)
例子:
f
=
open
(
r"C:\Users\Lenovo\Desktop\老师.txt"
,
'w'
,
encoding
=
"utf-8"
)
f
.
write
(
'石头0本'
)
#使用with关键词打开文件,只读模式
#使用for遍历文件
#判断“小郭10本”在不在文件中
#如果在文件中就打印(存在)
\ No newline at end of file
diy.py
View file @
7e1aeb4c
with
open
(
r"C:\Users\Lenovo\Desktop\晓芹.txt"
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
a
=
f
.
readlines
()
list
=
[]
for
i
in
a
:
q
=
i
.
split
()
sum
=
0
for
he
in
q
[
1
:]:
sum
=
sum
+
int
(
he
)
zuhe
=
q
[
0
]
+
str
(
sum
)
+
'
\n
'
list
.
append
(
zuhe
)
with
open
(
r"C:\Users\Lenovo\Desktop\晓芹.txt"
,
"a"
,
encoding
=
"utf-8"
)
as
f
:
f
.
writelines
(
list
)
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