使用ImmutableOrderedMultiDict读取文本文件,并在python中解析为dict

时间:2017-01-18 22:22:17

标签: python

我目前有一个文本文件,其中包含以下数据的行

ImmutableOrderedMultiDict([('txn_type', u'subscr_signu'), ('subscr_id', u'123123'), ('last_name', u'nar'), ('residence_country', u'US'), ('mc_currency', u'USD'), ('item_name', u'Upgrade'), ('business', u'example@example.com'), ('amount3', u'5.00'), ('recurring', u'1'), ('verify_sign', u'asdfasdddd'), ('payer_status', u'verified'), ('test_ipn', u'1'), ('payer_email', u'john@example.com'), ('first_name', u'John'), ('receiver_email', u'email@example.com'), ('payer_id', u'1N1nn'), ('reattempt', u'1'), ('charset', u'windows-1252'), ('notify_version', u'3.8'), ('period3', u'1 M'), ('mc_amount3', u'5.00'), ('ipn_track_id', u'123111111111')])

这是out.txt我试图让我的python程序打印txn_type但是继续 TypeError: string indices must be integers, not str

from werkzeug.datastructures import ImmutableOrderedMultiDict
lines = []

with open("out.txt") as f:
    for line in f:
        try:
            lines.append(line)
        except:
            pass

for i in lines:
    print(i['txn_type'])
    break

1 个答案:

答案 0 :(得分:0)

正如@ juanpa.arrivillaga在评论中所说,Dim wsSheet1 As Worksheet Dim wsSheet2 As Worksheet Set wsSheet1 = wbBook1.Worksheets("Sheet1") Set wsSheet2 = wbBook2.Worksheets("Sheet1") 做了伎俩

相关问题