python 中如何把TXT的每一行的三個元素儲存為乙個字典?

時間 2021-06-17 18:43:12

1樓:

dictlist=

with

open

("test.txt")as

fd:lines=fd

.readlines

()for

line

inlines

:line

=line

.strip

()dictlist.()

print

(dictlist)

2樓:

import

pandas

aspddf=

pd.read_csv

('test.txt'

,names=[

'ip'

,'name'

,'password'

],sep

=' ')df

'''ip name password0 1.1.1.

1 user1 password11 2.2.2.

2 user24 password22 3.3.3.

3 user3 password3'''df.T

.to_dict

()'''

,1: ,

2: }

'''Python 教程 - 蓋若

3樓:麟瀾

找到了乙個不用字典的簡單方法,若是有字典的法子誰也寫下t = open ('tel_ip.txt')for i in t.readlines():

a = (i.split()[0])

b = (i.split()[1])

c = (i.split()[2])

print (a)

print (b)

print (c)

python 如何讀取txt檔案中的數字並轉換成list?

已登出 with open nums.txt r as f content f.read lines line.split for line in content.split n lst for line in lines lst line print lst 測試 txt 檔案 執行結果 與其他答...

Python3 5中如何將矩陣寫入txt檔案?

WittFan 蝸殼看了樓上蝸殼的回答,我也寫了個完美版的,如下。You know,live and learn filename company matrix.txt with open filename,w as file object 將檔案及其內容儲存到變數file object 寫入第一行...

怎麼用python統計乙個txt檔案中的三個中文名字出現的次數?

coder 謝公子 import re text open text.txt r read name 張飛 關羽 劉備 for i in name result re.findall i,text print i,出現了 d次 len result z666 text open 路徑,encodin...