Newbie question

Dennis Lee Bieber wlfraed at ix.netcom.com
Wed Jan 26 23:29:44 EST 2000


On Thu, 27 Jan 2000 02:31:13 GMT, Scott Johnson  <sjohnson at csnet.net>
declaimed the following in comp.lang.python:

> My background is in MVS Cobol, CICS & Visual Basic.
> I have played a little with java & Perl.
> I have an understanding of classes & their properties & methods.
> Could someone explain to me the concept of .self ?

	Hmmm, Of those mentioned I though Java was supposed to be OO...
Doesn't it have a means of referring to the invoking instance from
inside a method?

	"self" is just a name, C++ commonly uses "this", and I'm sure
some language likes "me".

	However, that argument position in a class method is filled with
the actual instance that has been invoked. (Apologies if my syntax is a
tad off here, I don't do enough to recall it without a cheat book)

Class AClass:
	def dosomething(self, data):
	#some thing or other
		self.what = data


	a = AClass()
	b = AClass()

	a.dosomething(x)
	b.dosomething(x)

	The calls to dosomething effectively turn into (if this were a
language like Ada):

		dosomething(a,x)
		dosomething(b,x)

	Without "self", the methods would be sharing data too.

--
 > ============================================================== <
 >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed at dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <



More information about the Python-list mailing list