Getting rid of module naming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 360monkey
    New Member
    • Feb 2010
    • 17

    Getting rid of module naming

    I have this program:
    Code:
    class Cabbage:
       def __init__(self, height, bobnum):
          self.h = self.height
          self.b = self.bobnum
    x = cabbage(3, 7)
    If i put in cabbage.x.h, it returns
    3
    I want to remove the need to type cabbage in this,so i can just put
    x.h and return
    3.

    Any help is appreciated
    Thanks
    Last edited by bvdet; Feb 2 '10, 11:08 PM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    That's how it is supposed to work. Your code had some problems though.
    Code:
    >>> class Cabbage:
    ... 	def __init__(self, height, bobnum):
    ... 		self.h = height
    ... 		self.b = bobnum
    ... 		
    >>> x = Cabbage(3, 7)
    >>> x.h
    3
    >>>
    Please use code tags when posting code.

    BV - Moderator

    Comment

    • 360monkey
      New Member
      • Feb 2010
      • 17

      #3
      Thank you for the answer! It works now and I can python away! Thanks!

      Comment

      Working...