Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

import arcpy.env as env

# Set the workspace environment to local file geodatabase

In 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 How can I do this (should I import as well?)? should I pass it by argument when calling a function from in 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...

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.