Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Get variable from another class
Very new to Python and programming in general. I've watched videos and read tutorials about class variables, but I can't get it through my head how to make "selection" from FileType available in coordpick:

Would appreciate some help!

import arcpy
import pythonaddins

class FileType(object):
    """Implementation for pasdamappa_addin.filetype (ComboBox)"""
    def __init__(self):
        self.items = [".tif", ".jp2", ".sid"]
        self.editable = False
        self.enabled = True

    def onSelChange(self, selection):
        coordpick.enabled = True
        print selection

class coordpick(object):
    """Implementation for pasdamappa_addin.coordpick (Tool)"""
    def __init__(self):
        self.enabled = False
        self.shape = 'NONE'  # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.

    def onMouseDownMap(self, x, y, button, shift):
        print str(x)[:3] + str(y + 10000)[:2] + selection
First of all, selection isn't in FileType. You don't save it as an instance attribute in onSelChange. You would probably want to initialize it to a null value as well:

class FileType(object):
    """Implementation for pasdamappa_addin.filetype (ComboBox)"""
    def __init__(self):
        self.items = [".tif", ".jp2", ".sid"]
        self.editable = False
        self.enabled = True
        self.selection = None   # initialize to None
    def onSelChange(self, selection):
        coordpick.enabled = True
        self.selection = selection   # save the value as an instance attribute.
Once you have an instance, you can get the attribute with the dot operator:

>>> ft = FileType()
>>> ft.onSelChange('spam')
>>> ft.selection
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to access class variable? instances vs class drSlump 5 473 Dec-11-2019, 06:26 PM
Last Post: Gribouillis
  accessing local variable outside class priyanka08 3 216 Sep-24-2019, 10:00 AM
Last Post: buran
  Get variable from class inside another class hcne 3 526 Mar-30-2019, 03:02 PM
Last Post: ichabod801
  Trying to set an instance variable to current value of a class variable ScottDiesing 3 532 Feb-15-2019, 03:12 PM
Last Post: ScottDiesing
  The self variable in a class..? mitmit293 3 443 Feb-08-2019, 02:42 AM
Last Post: stullis
  Instantiating class from the string variable voltron 4 1,485 Feb-05-2018, 01:18 PM
Last Post: voltron
  What would be a way to check if a variable or class existed in an if? Klar 8 1,303 Dec-28-2017, 08:19 PM
Last Post: nilamo
  Can access class private variable? Michael 2 2,525 Aug-11-2017, 01:59 PM
Last Post: snippsat

Forum Jump:

Users browsing this thread: 1 Guest(s)