我需要從多個JPG文件的圖像標題信息提取到一個文本或日誌文件,但是當我運行下面的代碼,我收到一個錯誤:保存圖像頭信息到一個文本文件
for root, dirs, filenames in os.walk(topdir):
for f in filenames:
print(topdir)
print(f)
log = open(topdir + f, 'r')
data = p.get_json(log)
formatted_data =((json.dumps(data, sort_keys=True,indent=4, separators=(',', ':'))))
print(data)
print ("There are " + str(len(header_dict)) + " items on the menu.")
我得到當我運行了以下錯誤:
C:/Users/richie/Desktop/work/imagej/test images and files/XX1
image_D2016-02-03T15-27-56-763207Z_4.jpg
Traceback (most recent call last):
File "C:\Users\richie\Desktop\work\header_dir.py", line 25, in <module>
log = open(topdir + f, 'r')
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/richie/Desktop/work/imagej/test images and files/XX1image_D2016-02- 03T15-27-56-763207Z_4.jpg'
如何打開圖像文件,以允許在for循環的功能,對其運行?
日誌=打開(TOPDIR + 「/」 + F, 'R') –