473,396 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Question about Objects - repost with correct email account

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 win32Type "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'

Jul 18 '05 #1
3 1230

"bas68" <ba***@cox.net> wrote in message
news:MGpvb.394$xV6.316@lakeread04...
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'
>



Hi,
getSomething is a callable attribute of class Test (i.e. a method),
so the expression:
x.getSomething
evaluates to the method itself, while
x.getSomething()
calls the method and therefore evaluates to the result of the method.
Regards,
Thorsten
Jul 18 '05 #2
bas68 wrote:
> x = Test("Microsoft Sucks")
> x.getSomething

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

'Microsoft Sucks'


You aren't calling getSomething. Try: x.getSomething()

yours,
Gerrit.

--
109. If conspirators meet in the house of a tavern-keeper, and these
conspirators are not captured and delivered to the court, the
tavern-keeper shall be put to death.
-- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Kom in verzet tegen dit kabinet:
http://www.sp.nl/

Jul 18 '05 #3
Because getSomething is a method you need to use:
x.getSomething()


--
Francis Barnhart
fr*****@francisbarnhart.com
http://francisbarnhart.com
AIM: FrAniMaL

"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety."
-- Benjamin Franklin, Historical Review of Pennsylvania, 1759
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
7
by: David Shorthouse | last post by:
I am attempting to create a "new account creation" asp, but would ideally like the routine to check the Access db for an existing email address and username (called UID below). The select query...
4
by: Jason Hihn | last post by:
I am trying to decide between using 1 account for web DB access, and doing the auth myself, or using the database's built in auth. It's more steps to use the database's, but its also more secure. ...
4
by: cmc | last post by:
Hi, I 'm new to DB2 (from Oracle background) and have some fundamental question. In Oracle, you create user account "within the database" to let user to logon to the database. There is no tie...
2
by: pauldepstein | last post by:
Suppose I have a class of objects which take an integer parameter. I can easily create an object with the required parameter as follows: name_of_class variable_name(integer_value); For...
29
by: MP | last post by:
Greets, context: vb6/ado/.mdb/jet 4.0 (no access)/sql beginning learner, first database, planning stages (I think the underlying question here is whether to normalize or not to normalize this...
23
by: Kenneth Brody | last post by:
Given the following: char *ptr1, *ptr2; size_t n; ptr2 = ptr1 + n; Assuming ptr1 is a valid pointer, is the following guaranteed to be true? (ptr2 - ptr1) == n
10
by: KarlM | last post by:
Hallo! System.Security.AccessControl.FileSecurity (GetAccessControl) works fine. Now I would like to use GetAccessControl for Active Directory Objects like computers. I've searched a lot but...
2
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.