anything like C++ references?

Tom Plunket tomas at fancy.org
Mon Jul 14 19:44:09 EDT 2003


Noah wrote:

> As others have explained, you just return the value.
> It's just a different point of view. Instead of
>     change (v)
> you have:
>     v = change (v)

Ahh, now I remember what I wanted to do, and you're right- it's
more verbose and didn't really seem to add anything.  I wanted to
in-place clamp integers in a range, or maybe they were even
member variables;

def Color:
   def SomeOperation():
      # modify self.r, g, b
      self.r = clamp(self.r, 0, 255)
      self.g = clamp(self.g, 0, 255)
      self.b = clamp(self.b, 0, 255)

...that was just more typing than I wanted at that point,
although I'm sure that the keystrokes I burned were more than
made up for by Python's allowing me to do:

   def clamp(val, lowVal, highVal):
      if (lowVal <= val <= highVal):
         return val

:)

-tom!




More information about the Python-list mailing list