Python - 文件到字典,具有键值对的特定子字符串

时间:2016-09-12 10:56:27

标签: python compare comparison substring

我有一个看起来像的文本文件:

AAAAA123123423452452BBBASDASAS323423423432
BBBBB453453453466123AAAAADDFFG6565656565665

...

我想用这个创建一个字典,每个行的切片都是这样的:

file.txt:

hash[123123] = "BBBASD"
hash[453453] = "AAAAAD"

我写过以下尝试,但到目前为止它还没有用。什么都不打印:

myhash{}
with open('file.txt') as fi:
    for life in fi:
        key = [line:6:13]
        value = [line:21:27]
        myhash[key] = value

print(myhash) 

有人可以帮忙吗?提前谢谢!

1 个答案:

答案 0 :(得分:2)

您应该使用:

Alias /phppgadmin “C:/xampp/phppgadmin/”
<Directory “C:/xampp/phppgadmin”>
AllowOverride AuthConfig
Require all granted
</Directory>

你可以在Python中获得关于字符串切片的more info here