Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

How to Properly Use env.scratchGDB to Gaurantee Write Access

$
0
0
In scripting business processes it is coming up again and again where I need an intermediate workspace to write data. I am trying to copy a table to the scratch workspace but it is placing the table into a dbf in the folder where the scratchGDB is located. Here is what I have:

Code:

import arcpy, arceditor, logging, datetime, os, smtplib
from arcpy import env
arcpy.env.overwriteOutput = True
InputPrefix = "Database Connections\\Sun130 - 5151.sde\\"
tblImplsblRd = InputPrefix + "GIS_INTERFACE.SAP_IMPLAUSIBLE_READS"
lclImplsblRd = env.scratchGDB + "SAP_IMPLAUSIBLE_READS"

def copyRows(src, trgt, cfg):
    try:
        arcpy.CopyRows_management(src, trgt, cfg)
        logging.info(": Copied %s to %s" %(src, trgt))

    except Exception as e:
        print e
        logging.error(": %s" %(e))
        msgTxtErr = msgTxtErr + "\n" + "* " + str(e)
        errValue = 1

copyRows(tblImplsblRd, lclImplsblRd, "")

print "done"

When I run this from a script exported from ModelBuilder it places the table into the temporary gdb:

Code:

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# temp.py
# Created on: 2013-04-29 10:29:12.00000
#  (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy


# Local variables:
GIS_INTERFACE_SAP_IMPLAUSIBLE_READS = "Database Connections\\Sun130 - 5151.sde\\GIS_INTERFACE.SAP_IMPLAUSIBLE_READS"
SAP_IMPLAUSIBLE_READS = "C:\\Users\\TDMC0\\AppData\\Local\\Temp\\scratch.gdb\\SAP_IMPLAUSIBLE_READS"

# Process: Copy Rows
arcpy.CopyRows_management(GIS_INTERFACE_SAP_IMPLAUSIBLE_READS, SAP_IMPLAUSIBLE_READS, "")

However if the path to the scratch GDB is hard-coded I will lose the ability to have a gauranteed space to write data. Would appreciate help getting this working correctly.

Viewing all articles
Browse latest Browse all 2485

Trending Articles