【问题标题】:Iterating through values (floats) in a container dictionary [closed]遍历容器字典中的值(浮点数)[关闭]
【发布时间】:2018-02-08 21:28:57
【问题描述】:

如何遍历浮动字典的值?

我有一个字典,它的多个值是我想根据键重命名的文件名。

for k,v in dictionary.iteritems():
print(k,v)

这给了我这个输出:

键.........,值

(20026308, u'1224, 1225')

...

现在我想说的是,对于每个值,检查目录中是否存在同名的文件。

photodir = "C:\Desktop\phototest" photosindir = glob.glob("C:\Desktop\phototest*.jpg")

【问题讨论】:

标签: python dictionary key-value-store


【解决方案1】:
import os
photodir = "C:\Desktop\phototest"
dict = {20026308 : u'1224, 1225'}
for k,v in dict.items():
    print(k,v)
    for photo_id in v.split():
        path_to_check = "C:\Desktop\phototest%s.jpg"%photo_id
        photo_exist = os.path.isfile(path_to_check)
        print(path_to_check, "exists : ", photo_exist)

给:

20026308 1224, 1225
C:\Desktop\phototest1224,.jpg exists :  False
C:\Desktop\phototest1225.jpg exists :  False

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 2017-05-06
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多