The following creates a table in memory as expected when executed in the Python window [ArcGIS Pro 2.9, Windows 10]:
arcpy.CreateTable_management('memory','dataTable')
When I try to do the same thing in a Python toolbox tool (.pyt), the table does not appear to be created in memory (or anywhere else), although the call does not generate an error:
import arcpy
class Toolbox(object):
def __init__(self):
self.label = 'Create table in memory toolbox'
self.tools = [CreateTable]
class CreateTable(object):
def __init__(self):
self.label = 'Create table in memory tool'
self.canRunInBackground = False
def getParameterInfo(self):
return None
def isLicensed(self):
return True
def updateParameters(self, parameters):
return
def updateMessages(self, parameters):
return
def execute(self, parameters, messages):
arcpy.CreateTable_management('memory','dataTable')
return
If I use a file GDB instead of memory, both approaches succeed. Insights?
-
When I run your code, the table appears in memory. How are you determining it is not there? Try arcpy.env.workspace = 'memory' and then arcpy.ListTables().Brennan– Brennan2022年08月17日 11:53:05 +00:00Commented Aug 17, 2022 at 11:53
-
You might check if it exists first, and delete it or give it a different name. Otherwise you may receive an error. If arcpy.Exists("memory\\dataTable"): arcpy.Delete_management("memory\\dataTable")dslamb– dslamb2022年08月17日 18:50:35 +00:00Commented Aug 17, 2022 at 18:50
1 Answer 1
Shout out to Brennan: setting env.workspace appears to be the answer. I had been using arcpy.Exists('dataTable') to determine whether the table had been created, but arcpy.ListTables() works too.
It's still curious that the behavior is different when executing the same command in the Python window - in that case not only is the table "found" by arcpy.Exists (without setting env.workspace), but it also immediately appears in the TOC as a "standalone table'.
Explore related questions
See similar questions with these tags.