def get_module_data_path(modname, relpath=None, attr_name='DATAPATH'):
 datapath = getattr(sys.modules[modname], attr_name, '')
 if datapath:
  return datapath
 else:
  datapath = get_module_path(modname)
  parentdir = osp.join(datapath, osp.pardir)
  if osp.isfile(parentdir):
   datapath = osp.abspath(osp.join(osp.join(parentdir, osp.pardir), modname))
  if (relpath is not None):
   datapath = osp.abspath(osp.join(datapath, relpath))
  return datapath

def get_module_data_path ( modname , relpath = None , attr_name = 'DATAPATH' ) : datapath = getattr ( sys . modules [ modname ] , attr_name , '' ) if datapath : return datapath else : datapath = get_module_path ( modname ) parentdir = osp . join ( datapath , osp . pardir ) if osp . isfile ( parentdir ) : datapath = osp . abspath ( osp . join ( osp . join ( parentdir , osp . pardir ) , modname ) ) if ( relpath is not None ) : datapath = osp . abspath ( osp . join ( datapath , relpath ) ) return datapath
return module *modname* data path note: relpath is ignored if module has an attribute named *attr_name* handles py2exe/cx_freeze distributions .