AnsweredAssumed Answered

Creating a geodatabase and setting it to env.workspace

Question asked by eric.eagle on Mar 23, 2017
Latest reply on Mar 25, 2017 by curtvprice

Any reason why this wouldn't be working?


import arcpy
import os

basedir = 'C:\\Temp'
gdb_name = 'TestGDB'
gdb = os.path.join(basedir, gdb_name)

if arcpy.Exists(gdb):
    arcpy.env.workspace = gdb
    gdb = arcpy.CreateFileGDB_management(basedir, gdb_name)
    arcpy.env.workspace = gdb


I must not be understanding how .Exists() resolves, for if the gdb already exists, it gives me:


arcgisscripting.ExecuteError: ERROR 000258: Output C:\Temp\TestGDB.gdb already exists

Failed to execute (CreateFileGDB)


If the gdb does not exist, it gives me:


RuntimeError: Object: Error in accessing environment <workspace>