anaconda 4.2.0 (64-bit)
python 3.5.2
關於csv檔案讀寫練習小系統。
程式如下:
import csv
import time
import sys
filename = 'ha.csv'
datas = [['hello', 'girl'],
['hi', 1],
['oh', 2],
['yeah', 3]]
with open(filename, 'w', newline='') as f:
w = csv.writer(f)
for row in datas:
w.writerow(row)
d =
for i in range(1):
with open(filename) as f:
datas = csv.reader(f)
for data in datas:
print(data)
# print(d)
with open(filename, 'w', newline='') as f:
w = csv.writer(f)
for row in d:
w.writerow(row)
time.sleep(1)
while true:
print('如果想清除資料,請輸入(y/y),如果想退出系統,請輸入(n/n): ')
a = input()
if (a == 'y') or (a == 'y'):
d =
with open(filename, 'w', newline='') as f:
w = csv.reader(f)
for row in d:
w.writerow(row)
print('資料已經清空!')
break
elif (a == 'n') or (a == 'n'):
print('資料保留,退出系統成功!')
sys.exit()
else:
print('請按要求輸入!')
我曾經跨過山和大海,也穿過人山人海,我曾經擁有著的一切,轉眼都飄散如煙,我曾經失落失望失掉所有方向,直到看見平凡才是唯一的答案。
——韓寒《平凡之路》
Python之操作csv檔案
本篇僅作為 記錄 usr bin python coding utf 8 author ruiming lin datetime 2021 01 25 14 51 description import requests from pyquery import pyquery as pq import...
python之模組csv之CSV檔案一次寫入多行
coding utf 8 python 27 xiaodeng csv檔案一次寫入多行 import csv csv檔案,是一種常用的文字格式,用以儲存 資料,很多程式在處理資料時會遇到csv格式檔案 files open test.csv wb writer csv.writer files wr...
python使用csv寫入csv檔案
沒什麼好說的,直接上 吧 with open file.csv w encoding utf 8 newline as csvfile writer csv.writer csvfile 首先是表頭 writer.writerow id name gender birthday rating 然後是...