Semantics question...

David Allen s2mdalle at titan.vcu.edu
Mon May 15 19:54:35 EDT 2000


Hello,

I've just picked up Python recently, and I have a question about why the syntax is
the way it is.  (No, I'm not going to ask about the enforced whitespace :)

When writing a method inside of an object, say, something like:

class Foobar:
	def bar(self, someNumber):
		self.internal_data = someNumber
		return(None)

why is it that python requires programmers to refer to class data by using the
object?  (as in, you have to say self.internal_data = someNumber.  You could
just say internal_data = someNumber but it wouldn't do what you wanted it to)

I ask this because no other OO language (or a language that happens to be
able to do OOP, I should rather say) that I have programmed in seems to 
require it.  Usually someobject.datafield is reserved for referring to static 
fields, not fields within an instance of an object.

I'm asking this really out of curiousity, and because I keep forgetting it.  I'd
be interested to hear why this is the way it is.  I keep making this mistake:

class Foobar:
	def something(self, number):
		self.number = number
	def printNumber(self)
		print number

which obviously won't fly, since "self.number" is defined but "number" isn't.

-- 
David Allen
http://opop.nols.com/
----------------------------------------
"So here's a picture of reality: (picture of circle with lots of sqiggles in it) As we all know, 
reality is a mess."
  -- Larry Wall (Open Sources, 1999 O'Reilly and Associates)




More information about the Python-list mailing list