Calling several scripts into another python script

11-13-2015 08:11 AM
New Contributor III


I am trying to update a python addin for ArcGIS, which is a toolbar with four buttons. Mostly what the buttons do is transfer data from multiple personal geodatabases to a single oracle database. I have one script for each button and I want to call these four scripts in a single script.

This is the script which I am trying to call the other four scripts into. The issue that I am having is that the from package import * is causing the four buttons to fall over (they appear as a red circle with a line through it and the word missing next to it). I have tried keeping all four scripts within a single script but I would prefer to keep them separate. Everything I try and do seems to cause the buttons to fall over, even if it is just adding a print statement.

I have tried putting print dir() after importing package. The classes from the four scripts are being imported fine as far as I can tell.

Can anyone see a reason why this script is causing the buttons in the toolbar to fall over?

I have included the script at the bottom which I copied from a similar question ( The and the four scripts (Append_Models_Oracle.pv,, and Import_Determinands_csv.pv) are all located within the package folder.

import arcpy
import pythonaddins
import os
import sys
import getopt
import fnmatch
import traceback
import pyodbc
import csv
from package import *
from datetime import datetime
import logging
class AppendModelsOracle(object):
    """Implementation for Append_Models_Oracle.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
class SAGIStoOracle(object):
    """Implementation for SAGIS_to_Oracle.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
class ImportGIS1CSV(object):
    """Implementation for Import_GIS1_CSV.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
class ImportDeterminandCSV(object):
    """Implementation for Import_determinand_csv.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):

def _import_package_files():
    """ Dynamically import all the public attributes of the python modules
        in this file's directory (the package directory) and return a list
        of their names.
    import os
    exports = []
    globals_ = globals()
    locals_ = locals()
    package_path = os.path.dirname(__file__)
    package_name = os.path.basename(package_path)
    for filename in os.listdir(package_path):
        modulename, ext = os.path.splitext(filename)
        if modulename[0] != '_' and ext in ('.py', '.pyw'):
            # create a package relative subpackage name
            subpackage = '{}.{}'.format(package_name, modulename)
            module = __import__(subpackage, globals_, locals_, [modulename])
            modict = module.__dict__
            names = (modict['__all__'] if '__all__' in modict else [name for name in modict if name[0] != '_'])  # public names
            globals_.update((name, modict[name]) for name in names)
    return exports
if __name__ != '__main__':
    __all__ = ['__all__'] + _import_package_files()  # '__all__' in __all__

Thanks in advance for any help,


0 Kudos
0 Replies