python 查詢固定檔案格式名稱

2022-04-11 20:03:42 字數 918 閱讀 1453

需求:找出所有的以result.json結尾的檔案,以便後續解析其中資料。

專案的目錄結構如下,json檔案內容如右下圖

#獲取../report目錄下的以-result.json結尾的檔案

files1 = [file for file in os.listdir('

../report

') if file.endswith('

-result.json')]

print

(files1)

#方法二使用glob(該庫可以使萬用字元)

files2 = glob.glob('

../report/*-result.json')

print

(files2)

#將檔案中的json資料反序列化為json物件,然後解析獲取其中資料

for a in

files1:

with open(

"../report/{}

".format(a), encoding='

utf-8

') as f:

r =json.load(f)

print(r['

name

'])輸出:

Python檔案格式轉換

將帶有點座標的 csv 轉 geojson,不帶其他屬性 import csv csv file open e test.csv encoding gbk csv reader csv.reader csv file geojson properties type feature float row...

Oracle 控制檔案格式ctl檔案格式

options skip 1,errors 10 load data characterset zhs16gbk infile into table table name truncate fields terminated by optionally enclosed by trailing nu...

檔案格式 gff格式

gff檔案格式 gff格式是 sanger 研究所定義,是一種簡單的 方便的對於 dna rna以及蛋白質序列的特徵進行描述的一種資料格式,已經成為序列注釋的通用格式,比如基因組的基因 許多軟體都支援輸入或者輸出gff格式。前格式定義的最新版本是版本3。原始定義見 song websitegff是存...