Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson23-diy1
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
f482ef75
authored
Aug 18, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
599ea45f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
21 deletions
my_csv.py
my_csv.py
View file @
f482ef75
import
csv
with
open
(
'score1.csv'
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
r
=
csv
.
reader
(
f
)
#读取文件的内容
r
=
list
(
r
)
#把读取到的数据转化成列表 list(变量)
pipi
=
r
[
7
]
#r列表的第7个索引
print
(
'皮皮的成绩是:'
,
pipi
)
print
(
'所有人的英语成绩'
)
for
i
in
r
:
print
(
i
[
3
])
#单行数据导入
a
=
[
1
,
2
,
3
,
4
]
with
open
(
'score2.csv'
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
w
=
csv
.
writer
(
f
)
#创建读写对象
w
.
writerow
(
a
)
#把列表数据加入到文件中
#多行写入
a
=
[
4
,
5
,
6
,
7
,
8
]
c
=
[
9
,
10
,
11
,
12
,
13
]
d
=
[
14
,
15
,
16
,
17
,
18
,
19
]
with
open
(
'score3.csv'
,
'w'
,
encoding
=
'utf-8'
,
newline
=
''
)
as
f
:
w
=
csv
.
writer
(
f
)
#创建读写对象
w
.
writerows
(
b
)
#把列表数据加入到文件中
with
open
(
'score1.csv'
,
'w'
,
encoding
=
'utf-8'
)
as
file
:
w
=
csv
.
writer
(
file
)
w
.
writerow
(
a
)
w
.
writerow
(
c
)
w
.
writerow
(
d
)
\ No newline at end of file
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