json檔案
import json
jsonfile =
open
('data_test.json'
,'rt'
,encoding=
'utf-8'
).read(
)data = json.loads(jsonfile)
for row in data:
print
(row)
python中json庫的loads函式接收字串,不接受檔案為引數,csv reader 接收乙個檔案物件作為引數
xml檔案
xml檔案中有兩個位置可以儲存值,其中乙個是兩個標籤之間,另乙個是作為標籤的屬性
xml檔案
#獲取文字
s = u.read(
).decode(
'gbk'
)root = et.fromstring(s)
#從跟節點迭代子節點
for elem in root.
iter()
:print
(elem.tag, elem.attrib)
#取所有的sales子節點迴圈
for item in root.iterfind(
'sales'):
#獲取兩列資料
print
(item.get(
"date"),
'\t'
,item.get(
"salesnum"
))
Python之資料處理
靠別人不如靠自己,學學學學學學學學!原資料 需求 coding utf 8 txtfile aminer1.txt newtxtfile open new txtfile,w with open txtfile,r as file to read lines file to read.readlin...
python之資料處理
檔案資料讀寫的基本操作 import this 本地檔案的界定 指向乙個本地儲存的檔案,是乙個連線或者乙個對映 path1 c users 11786 desktop test.txt 正斜線兩個或者反斜線乙個來用於資料路徑的表達 再或者用r 寫在檔案路徑外面 推薦第三種 path2 c users...
資料互動之資料處理
資料互動必須通過協議來實現,所以互動雙方必須遵循一定的讀寫規則 我的方法很簡單但可以用,如果大家有好的方法,不妨交流一下 實現方法 資料流類datastream有兩個char 型指標,分別用來儲存讀寫的資料,還有w pos,r pos兩個資料用來記錄讀寫的位置,而且要用到互斥鎖,確保指標的安全性 v...