Question about Objects

Discussion in 'Python' started by campbell95, Nov 21, 2003.

  1. campbell95

    campbell95 Guest

    I've been hacking visual basic for several years and understand the basic
    concepts of OOP. That said, I'm stumped here with the Python Class.

    Here is the Class...

    >class Test:
    > def __init__(self, something):
    > self.something = something
    >
    > def getSomething(self):
    > return self.something


    This is what I get when I test it. Why does <getSomething> not return the
    value of <something>? is obvious that <something> has a value. I fear this
    is a simple oversight but I've racked my brain for hours looking at online
    doc's and examples. Thanks for any help!!

    >Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on

    win32
    >Type "copyright", "credits" or "license()" for more information.
    >****************************************************************
    >IDLE 1.0 ==== No Subprocess ====
    >>>>
    >>>> x = Test("Microsoft Sucks")
    >>>> x.getSomething

    ><bound method Test.getSomething of <__main__.Test instance at 0x00C01940>>
    >>>> x.something

    >'Microsoft Sucks'
    >>>>
    campbell95, Nov 21, 2003
    #1
    1. Advertising

  2. campbell95

    Mark Roach Guest

    On Fri, 21 Nov 2003 09:56:07 -0500, campbell95 wrote:

    > I've been hacking visual basic for several years and understand the basic
    > concepts of OOP. That said, I'm stumped here with the Python Class.

    [...]
    >> def getSomething(self):
    >> return self.something

    [...]
    >>>>> x.getSomething

    >><bound method Test.getSomething of <__main__.Test instance at 0x00C01940>>


    you need to actually call the method: x.getSomething()

    -Mark
    Mark Roach, Nov 21, 2003
    #2
    1. Advertising

  3. On Fri, 21 Nov 2003 09:56:07 -0500, "campbell95" <> wrote:

    >This is what I get when I test it. Why does <getSomething> not return the
    >value of <something>? is obvious that <something> has a value. I fear this
    >is a simple oversight but I've racked my brain for hours looking at online


    It is. ;-)

    >doc's and examples. Thanks for any help!!
    >
    >>Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on

    >win32
    >>Type "copyright", "credits" or "license()" for more information.
    >>****************************************************************
    >>IDLE 1.0 ==== No Subprocess ====
    >>>>>
    >>>>> x = Test("Microsoft Sucks")
    >>>>> x.getSomething

    >><bound method Test.getSomething of <__main__.Test instance at 0x00C01940>>


    Remember, this isn't VB: you can't leave the parens off when calling a method.
    There's no difference between subs and functions in Python, and you must
    include the parens if you want to _call_ the function and get the value.
    Otherwise you get the function.

    It makes sense, it just that you're used to the peculiar MS-way of doing
    things. Your mind will heal, don't worry. ;-)
    Fernando Rodriguez, Nov 21, 2003
    #3
  4. campbell95

    bas68 Guest

    Great community, glad I stopped in. Thanks for all the help!

    "Fernando Rodriguez" <> wrote in message
    news:p...
    > On Fri, 21 Nov 2003 09:56:07 -0500, "campbell95" <>

    wrote:
    >
    > >This is what I get when I test it. Why does <getSomething> not return the
    > >value of <something>? is obvious that <something> has a value. I fear

    this
    > >is a simple oversight but I've racked my brain for hours looking at

    online
    >
    > It is. ;-)
    >
    > >doc's and examples. Thanks for any help!!
    > >
    > >>Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on

    > >win32
    > >>Type "copyright", "credits" or "license()" for more information.
    > >>****************************************************************
    > >>IDLE 1.0 ==== No Subprocess ====
    > >>>>>
    > >>>>> x = Test("Microsoft Sucks")
    > >>>>> x.getSomething
    > >><bound method Test.getSomething of <__main__.Test instance at

    0x00C01940>>
    >
    > Remember, this isn't VB: you can't leave the parens off when calling a

    method.
    > There's no difference between subs and functions in Python, and you must
    > include the parens if you want to _call_ the function and get the value.
    > Otherwise you get the function.
    >
    > It makes sense, it just that you're used to the peculiar MS-way of doing
    > things. Your mind will heal, don't worry. ;-)
    >
    bas68, Nov 21, 2003
    #4
  5. bas68 wrote:
    > Great community, glad I stopped in. Thanks for all the help!
    >

    You're welcome !-) And yes, this is probably one of the friendliest
    places on usenet (thanks you all python-lovers BTW).

    (But please edit out irrelevant parts of the posts you're answering to
    !-)

    (snip other posts)

    Bruno
    Bruno Desthuilliers, Nov 21, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bigbinc
    Replies:
    3
    Views:
    389
    Michael Borgwardt
    Nov 18, 2003
  2. Simon Elliott

    Inheritance of objects within objects

    Simon Elliott, Dec 10, 2004, in forum: C++
    Replies:
    2
    Views:
    326
    Simon Elliott
    Dec 10, 2004
  3. =?Utf-8?B?c3RldmVuIHNjYWlmZQ==?=

    form objects into class objects

    =?Utf-8?B?c3RldmVuIHNjYWlmZQ==?=, Jul 5, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    424
    =?Utf-8?B?c3RldmVuIHNjYWlmZQ==?=
    Jul 6, 2006
  4. JoeC
    Replies:
    6
    Views:
    310
    kwikius
    Oct 5, 2006
  5. 7stud
    Replies:
    11
    Views:
    674
    Dennis Lee Bieber
    Mar 20, 2007
Loading...

Share This Page