In case anyone is looking for that Python template webpage, it can be found here:
https://web.archive.org/web/20151217180732/http://blogs.esri.com:80/esri/arcgis/2011/08/04/pythontemplate/
This thread is 9 years old Andres Castillo python 3 had only been out for less than a year
This Esri documentation may be of use in this topic as well:
Extending geoprocessing through Python modules—Geoprocessing and Python | Documentation
When I import a module I've written, I also like to reload the module to update any changes I may have made to it, so:sys.path.append(r'modulePath')import modulereload(module)
Fraxinus: you can also import a toolbox and run a script (in the toolbox) that way.
import script2.py
It easiest just to put your module in one of these default paths. However, if you make your own module, and say want to put it out on a network location somewhere:import sysnetworkPath = r"\\mynetwork\gis\py_files" #aka the folder where the mymodule.py file is locatedsys.append(networkPath)import mymodulemymodule.myFunction(arg1,arg2)
''' Main_program.py demonstrates how to import and call functions from another module ''' import CallingFunctions a_list = [1,2,3,4,5,6,7,8,9,10] print CallingFunctions.func1(a_list) print CallingFunctions.func5(a_list) print CallingFunctions.func8(a_list)
''' Callingfunctions.py imported into another program giving it access to the functions ''' def func1(inputs=None): x = sum(inputs) return "sum some numbers: ", x ''' more functions ''' def func5(inputs=None): x_sq = 0 for x in inputs: x_sq += x**2 return "sum of squares: ", x_sq ''' more functions ''' def func8(inputs=None): return "hello from 8: ", inputs ''' more functions ''' if __name__ == "__main__": a_list = [1,2,3,4,5,6,7,8,9,10] inputs = "test inputs" a_dict = {1:[func1([1,2,3]) ], 5:[func5([1,2,3])], 8:[func8("inputs to 8")]} needed = [1,5,8] for akey in needed: if akey in a_list: action = a_dict[akey] print "\naction: ", action
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.