目前我得到以下錯誤替代cmp從python 2移動到3?小蟒蛇的經驗。
Traceback (most recent call last):
File "C:\Users\Dilshad\Desktop\project_7-8-2015\8_bands\Program_camera.py", line 47, in <module>
if (cmp(before, after) != 0):
NameError: name 'cmp' is not defined
當我運行:
# CAMERA IMAGE ANALYZE
camera_directory = "/Users/Dilshad/Dropbox/Camera Uploads" # Directory of camera uploads
os.chdir(camera_directory) # Change directory to location of photo uploads
path = "."
before = dict([(f, None) for f in os.listdir(path)])
print('Waiting for image to be uploaded...\n')
while True: # Wait a new image in the directory
import time
time.sleep(2)
after = dict([(f, None) for f in os.listdir(path)])
if (cmp(before, after) != 0):
break;
print('New file detected.\n') # New image detected
我知道CMP是由蟒蛇3下降,我嘗試了建議(A> B) - (一< b)由通過什麼之後代入(前>)在Python 3的新功能 - (<之後),但我得到以下幾點:
Traceback (most recent call last):
File "C:\Users\Dilshad\Desktop\project_7-8-2015\8_bands\Program_camera - test.py", line 46, in <module>
if ((before > after) - (before < after) != 0):
TypeError: unorderable types: dict() > dict()
任何想法上我如何完成這個比較?