1

I have some scripts that are constantly setting env.workspace of arcpy. Usually, I have a caller script(script1.py) that may call some other script (script2.py). I've created a file globals.py with the paths that never change:

import arcpy.env as env
rootPath="S:/workspace/MSc_git/ArcGis/"
layersPath=rootPath+'Layers/'
# Set the workspace environment to local file geodatabase
env.workspace=rootPath+'estagio_db.gdb'

In script1.py I have something like this:

import arcpy
import globals as g
from arcpy import da
arcpy.AddMessage("Importing arcpy outside ArcMap took %s seconds." % (time.clock() - t_start))
from cProfile import run
def main():
 ....

And I need to use env.workspace and sometimes the layerspath inscript2.py How can I do this (should I import gloabl.py as well?)? should I pass it by argument when calling a function from script2.py in script1.py or is there any other way to accomplish this?

I know we should avoid global vars, but in this case, and since I need to centralize its definition I don't know how to do it well...

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Aug 9, 2013 at 13:31

1 Answer 1

2

I think a global in this case is fine, as you are using arcpy and by setting arcpy.workspace you're setting a giant global in arcpy anyway (which is bad library design but I digress)

Personally I would be passing in the values you need into script2 functions as it will make your code cleaner as you are reducing the reliance on global vars.

answered Aug 9, 2013 at 13:59

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.