1

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?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 16, 2022 at 18:22
2
  • 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(). Commented 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") Commented Aug 17, 2022 at 18:50

1 Answer 1

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'.

answered Aug 18, 2022 at 5:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.