I am having trouble with the arcpy.Exists() function in a script to check the existence of a table in a personal geodatabase. When I test in the ArcToolbox Python window, I get the correct result, True, for a table that exists. When I use the same commands in a stand-alone script, regardless of how I construct the path string, it always returns False for the table. I also tested just the geodatabase, and it returns True, so it is not having trouble finding the geodatabase itself.
Below is the code from the script. When I run from the interactive window, I just remove the print statement.
import arcpy
print arcpy.Exists("Y:/projects/dnr_svmp2016/db/SVMP_2000_2015_DB.v52_20170803/SVMP_DB_v5.2_20170803_AB.mdb/site_samples")
print arcpy.Exists("Y:\projects\dnr_svmp2016\db\SVMP_2000_2015_DB.v52_20170803\SVMP_DB_v5.2_20170803_AB.mdb\site_samples")
print arcpy.Exists("Y:\\projects\\dnr_svmp2016\\db\\SVMP_2000_2015_DB.v52_20170803\\SVMP_DB_v5.2_20170803_AB.mdb\\site_samples")
print arcpy.Exists("Y:/projects/dnr_svmp2016/db/SVMP_2000_2015_DB.v52_20170803/SVMP_DB_v5.2_20170803_AB.mdb")
This script returns:
False
False
False
True
Here is screenshot of the interactive window:
I'm hoping that the solution is something very obvious that I am just missing right now! Thanks for any help.
Solved! Go to Solution.
Ah ha! Thank you Joshua! That solved it. Really helpful info.
So, that explains why similar code I wrote (using arcpy.Exists) for the Validator of the Toolbox worked and this code didn't.
I don't remember changing/updating the interpreter in PyCharm -- it may have happened when I upgraded recently without me realizing it.
grief python interpreters... why doesn't everything move to Anaconda and python 3.x
I firmly believe 10.6 will stay with Python 2.x, which opens the door to ArcMap never going to 3.x. Pro is getting closer, but we still have too many workflows that can't be migrated cleanly between ArcMap to Pro, thus slowing the adopting of Pro in the organization.
Like Y2K ... I still have Cobol friends making a living
Totally unrelated to your question, but a tip that might help in future...
When I run from the interactive window, I just remove the print statement.
I use a small function in every script (actually, in a custom utils.py that I have many utils) that I can use for either the interactive window or a script, without having to change print to arcpy.AddMessage
import arcpy
def myMsgs(message):
arcpy.AddMessage(message)
print(message)
myMsgs("my message here, with {0} formatiing if needed".format("fancy"))
I have a version that will add the date/time to the message, but that takes a few more steps. This is handy if switching between, especially when developing/debugging. just an fyi.