我正式迷路了。我有一条微不足道的python,它检查文件是否存在。路径存储在字典中。
当我执行下一行代码时,它返回false:
if not os.path.exists(self.parameters['icm_profile']):
raise FileDoesNotExistError(PreprocessingErrors.FileNotPresent, "icm profile {} not found".format(self.parameters['icm_profile']))
当我复制“确切的字符串”并执行下一行时,它返回true:
if not os.path.exists("S:\\IAI\\Data\\Recipes\\BGD\\Inkjet\\LPI\\CMY_360x720dpi_2dpd_profilev6.icm"):
print("aap")
因此,路径确实存在。
我能想到的没有什么不同...我在做错什么呢?
答案 0 :(得分:1)
对我来说,好像您那里有多余的一对引号可能会引起您的麻烦。试试:
self.parameters['icm_profile'][1:-1]
DeepSpace提到的另一种方法是使用
self.parameters['icm_profile'].strip('"')
或者如果您真的很偏执
self.parameters['icm_profile'].strip('"').strip("'")