Python 如果匹配文件名不匹配';不存在

Python 如果匹配文件名不匹配';不存在,python,arcmap,Python,Arcmap,我有以下代码,由于某种原因,我无法返回并检查下一个FC名称。在我添加if“os.path.exists()”和if(如果两个文件夹中都存在所有文件)之前,这段代码非常有效。请指出问题所在。谢谢 import arcpy from arcpy import env import os arcpy.env.overwriteOutput = True Match_FC=arcpy.GetParameterAsText(0) Matched=Match_FC[-10:-1] arcpy.AddMess

我有以下代码,由于某种原因,我无法返回并检查下一个FC名称。在我添加if“os.path.exists()”和if(如果两个文件夹中都存在所有文件)之前,这段代码非常有效。请指出问题所在。谢谢

import arcpy
from arcpy import env
import os
arcpy.env.overwriteOutput = True
Match_FC=arcpy.GetParameterAsText(0)
Matched=Match_FC[-10:-1]
arcpy.AddMessage
env.workspace =arcpy.GetParameterAsText(1)
output=arcpy.GetParameterAsText(2)
fcList = arcpy.ListFeatureClasses()
for fc in fcList:
 if os.path.exists(fc==Matched):
    if fc[-10:-1]==Matched:
      arcpy.MakeFeatureLayer_management(fc, output,'','','')
 pass

代码显示
os.path.exists(fc==Matched)
-注意==。表达式
fc==Matched
可以是True或False,因此您要检查True或False是否作为路径存在

它们可能不存在,这就是为什么您永远不会进入if的原因。

os.path.exists()获取文件系统上的路径并检查它是否存在,然后向它提供bool值

例如:
os.path.exists('/path/to/my/file')
如果
file
存在,则返回
True

编辑: 我想你会这样做:

for fc in fcList:
    if fc == Matched:
        # do sth if matched
    else:
        # do sth if not matched. If you don't need else branch just delete it, without pass

在调用
exists
时,您打算
fc==Matched
做什么?所以我应该只使用一个=符号。我可以在循环内使用if“fcMatched:然后”Pass“吗?对不起,我不明白您的意思。什么是?
Pass
在这里很有用。我想说的是,如果不等于。