当我尝试在Python中使用csv.writer()时显示错误,声称csv模块中不存在该函数,我该怎么办?

0 投票
0 回答
21 浏览
提问于 2025-04-11 22:14

这是我的代码:

import csv
def addr():
    with open('csvfile.csv','a',newline='') as f:
        w=csv.writer(f,delimiter=',')
        tid=int(input('Teacher ID: '))
        nm=input('Enter Name: ')
        mo=int(input('Mobile Number: '))
        w.writerow(tid,nm,mo)
def countr():
    with open('csvfile.csv') as f:
        c=csv.rowcount
        print('Number of records:',c)
while True:
    addr()
    if input('Do you Wish to Continue? (Y/N): ').lower() in ('n','no'):
        break

在这里输入图片描述

当我尝试使用普通的 file.write() 时,没有显示任何错误。

0 个回答

暂无回答

撰写回答