python os.path.exists返回false

python os.path.exists返回false,python,Python,我正式迷路了。。我有一个简单的python检查文件是否存在。路径存储在字典中 当我执行下一行代码时,它返回false: if not os.path.exists(self.parameters['icm_profile']): raise FileDoesNotExistError(PreprocessingErrors.FileNotPresent, "icm profile {} not found".format(self.parameters['icm_profile']))

我正式迷路了。。我有一个简单的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")
因此,路径确实存在

我想不出有什么不同。。。我到底做错了什么


在我看来,你有一对额外的引号,这可能会给你带来麻烦。尝试:

self.parameters['icm_profile'][1:-1]
DeepSpace提到的另一种方法是使用

self.parameters['icm_profile'].strip('"')
或者如果你真的很偏执

self.parameters['icm_profile'].strip('"').strip("'")

在断言self.parameters['icm_profile']==“S:\\IAI\\Data\\Recipes\\BGD\\Inkjet\\LPI\\CMY\u 360x720dpi\u 2dpd\u profilev6.icm”上会发生什么?您的路径包含引号。请注意它是如何以“
”开头,以“
”结尾的。
@aranfey对,我想这是我对显而易见的事情视而不见的。。谢谢如果有一天没有报价会发生什么?(我们不知道
self.parameters
来自哪里)。更好的解决方案是
self.parameters.strip(“”)
Aha,就是这样。非常感谢!!我引用了客户端应用程序中的路径,但这不是必需的。我可以在那里删除它,就像将路径添加到字典中一样(作为字符串)已经添加了引号。再次感谢,我忽略了1000次…@DeepSpace另一方面,
strip
可能会为一些奇怪的filname去掉太多引号。:)我认为这是你必须假设你知道在某些约束下的行为之一,可能是在单元测试领域