473,408 Members | 1,876 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,408 software developers and data experts.

Question about Objects

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
4 1185
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
Jul 18 '05 #2
On Fri, 21 Nov 2003 09:56:07 -0500, "campbell95" <ca********@cox.net> 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. ;-)

Jul 18 '05 #3
Great community, glad I stopped in. Thanks for all the help!

"Fernando Rodriguez" <fr*@easyjob.net> wrote in message
news:ph********************************@4ax.com...
On Fri, 21 Nov 2003 09:56:07 -0500, "campbell95" <ca********@cox.net> 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 thisis 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)] onwin32
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. ;-)

Jul 18 '05 #4
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

Jul 18 '05 #5

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

Similar topics

4
by: Joseph Geretz | last post by:
Our company develops and markets a client/server application which is written in VB6 as a rich Win32 Client/Server application. For a variety of technological reasons we are looking to migrate...
6
by: Kay | last post by:
Hello, My question isn't specific to .Net but as .Net is object oriented, I would be interested if someone could let me know if there is a standard way of implementing what I describe below in...
3
by: pertheli | last post by:
Hello, I have a large array of pointer to some object. I have to run test such that every possible pair in the array is tested. eg. if A,B,C,D are items of the array, possible pairs are AB, AC,...
1
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage...
21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
3
by: Miguel | last post by:
Hi all friends: It's said that Sessions objects in ASP 3.0 with IIS 5.0 occupy certain memory of the machine which take to take care about use a lot of Sessions objects in the ASPs pages of the...
4
by: phl | last post by:
hi, My question is: 1. To avoid possible memory leaks, when you use this pattern, after you have dealth with the unmanaged resources and before you take your object off the finalize queue,...
10
by: mg | last post by:
I'm migrating from VB6 and have a question about using 'Using' and the best way to use it. Here is a example of a small bit of code: dbConx("open") Using CN Dim CMD As New OleDbCommand(sSQL,...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
13
by: John Kraft | last post by:
Friends, I'm working on some crud stuff, and I was looking for opinions on the subject. Below, I have pasted some VERY simple sample code. Class2 is a "traditional" crud type object. In a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.