arcpy.Exists working in interactive window but not stand-alone script

1773
14
Jump to solution
09-01-2017 11:25 AM
AllisonBailey
New Contributor III

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:

Screen shot of same commmands in ArcToolbox Python window

I'm hoping that the solution is something very obvious that I am just missing right now!   Thanks for any help.

Tags (1)
0 Kudos
14 Replies
AllisonBailey
New Contributor III

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.   

0 Kudos
DanPatterson_Retired
MVP Emeritus

grief  python interpreters... why doesn't everything move to Anaconda and python 3.x

JoshuaBixby
MVP Esteemed Contributor

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.

DanPatterson_Retired
MVP Emeritus

Like Y2K ... I still have Cobol friends making a living

Python countdown

RebeccaStrauch__GISP
MVP Emeritus

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.