Accessing objects &attributes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GTAPy
    New Member
    • Mar 2008
    • 6

    Accessing objects &attributes

    Hello Python Dev.

    i am new to Python, i am stuck in one of the classes instantiation with confusing __init__ , here the details : i have 2 classes
    [PHP]
    Class A:

    def __init__(self):

    self.service = None
    self.currentVer Map = None
    self.map= None
    self.Name1 = None
    self.Name2 = None
    .
    .
    .
    etc


    def AX (self, name):
    self.somevalue = gold

    return self.somevalue


    Class B (wx.Frame) :
    def __init__(self, parent, id=wx.ID_ANY, title='', pos=wx.DefaultP osition,
    size=(700,650), style=wx.DEFAUL T_FRAME_STYLE):

    wx.Frame.__init __(self, parent, id, title, pos, size, style)


    def __BY (self, somevalue):

    "all i need inside this method is getting
    GOLD value from Class A, method AX and use it
    inside BY method"

    [/PHP]

    i appreciate any help !

    Thanks,
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by GTAPy
    Hello Python Dev.

    i am new to Python, i am stuck in one of the classes instantiation with confusing __init__ , here the details : i have 2 classes
    [code=Python]
    Class A:

    def __init__(self):

    self.service = None
    self.currentVer Map = None
    self.map= None
    self.Name1 = None
    self.Name2 = None
    .
    .
    .
    etc


    def AX (self, name):
    self.somevalue = gold

    return self.somevalue


    Class B (wx.Frame) :
    def __init__(self, parent, id=wx.ID_ANY, title='', pos=wx.DefaultP osition,
    size=(700,650), style=wx.DEFAUL T_FRAME_STYLE):

    wx.Frame.__init __(self, parent, id, title, pos, size, style)


    def __BY (self, somevalue):

    "all i need inside this method is getting
    GOLD value from Class A, method AX and use it
    inside BY method"

    [/code]

    i appreciate any help !

    Thanks,
    Please use python code tags. Class should not be capitalized. In class definition 'A', you should inherit from object to conform to new style classes. Name gold needs to be defined. Since AX() is a method, create an instance of A to access it.[code=Python]
    class A(object):
    def __init__(self):
    self.value = None

    def AX(self, name):
    self.somevalue = 'gold'
    return self.somevalue

    class B(object):
    def __init__(self, val):
    self.val = val

    def __BY(self, somevalue):
    val = A().AX('name')
    return val

    >>> print B(1)._B__BY(1)
    gold
    >>> [/code]

    Comment

    • GTAPy
      New Member
      • Mar 2008
      • 6

      #3
      Thanks for reply ,

      but in class B i have already __init__ that doing other stuff as you can see the code , so should i create another __init__ (self, value) ? or add it to the current __init__ in class B ?

      Thanks,

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        Originally posted by GTAPy
        Thanks for reply ,

        but in class B i have already __init__ that doing other stuff as you can see the code , so should i create another __init__ (self, value) ? or add it to the current __init__ in class B ?

        Thanks,
        I only showed the __init__() method in class B for demonstration purposes. The instance of A is created in __BY() to access method A().AX().

        Comment

        Working...