# 第一题
fp=open(r'C:\Users\CY\Desktop\first.txt','w')
fp.write('name,sex\n')
fp.write('攀攀,男')
fp.close()
# 第二题
import csv
fp=open(r'C:\Users\CY\Desktop\first.txt','r')
fp1=open(r'C:\Users\CY\Desktop\second.csv','w',newline='')
writer=csv.writer(fp1)
for content in fp:
writer.writerow((content.split(',')[0],content.split(',')[1]))
fp.close()
fp1.close()
网友评论