Thread: Python OOP

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Canada
    Posts
    242
    Rep Power
    0

    Python OOP


    How come Python never implemented a ``stronger'' (is that the right word?) OOP system (ie. more like C++/Java) with private/public stuff?
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    Python does have private and public methods (no protected though). If you prefix a method name with __, then it is only visible within that class.
    Code:
    class class1:
        def method1(self):
            print "Hello from Method 1"
        def __method2(self):
            print "Method 2"
        def method3(self):
            self.__method2()
    In the above code, method1() and method3() are public and can be accessed from other modules, but __method2() can only be accessed from within this class.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Canada
    Posts
    242
    Rep Power
    0
    Woah, I never new that . Is it the same for variables?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    13
    Originally Posted by NetBSD
    How come Python never implemented a ``stronger'' (is that the right word?) OOP system (ie. more like C++/Java) with private/public stuff?
    Because it's not useful to artificially restrict the visibility to things within classes. Especially not in a language like Python.
    Debian - because life's too short for worrying.
    Best. (Python.) IRC bot. ever.

IMN logo majestic logo threadwatch logo seochat tools logo