Why self?

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Wed Jul 10 14:25:54 EDT 2002


Andrae Muys <amuys at shortech.com.au> wrote:
>"Louis M. Pecora" <pecora at anvil.nrl.navy.mil> wrote in message news:<090720021439257166%pecora at anvil.nrl.navy.mil>...
>> scientifc code and I just think
>> 
>> 
>>    self.y= self.x**2 * self.t/self.z + self.a * FFT(self.tseries)
>> 
>> is a LOT uglier than
>> 
>>    y= x**2 * t/z + a * FFT(tseries)
>
>In fact the only reason I have followed this thread is because I found
>myself writing some similar code just the other day and came to the
>same conclusion.  Python loves namespaces right?  Now I haven't given
>much thought to it, but it occurs to me to ask why Python dosn't
>provide support for using namespaces, not just defining them?
>
>Compare the following:
>
>self.y= self.x**2 * self.t/self.z + self.a * FFT(self.tseries)
>
>to:
>
>y= x**2 * t/z + a * FFT(tseries)
>
>to:
>
>with self:
>    y= x**2 * t/z + a * FFT(tseries)


The Pythonic way to use namespace is :-)

from self import x, y, z, a, tseries
y= x**2 * t/z + a * FFT(tseries)
to self export y  

Any change that persists beyond local namespace is mentioned explicitly.
Does it solve all the problems mentioned below?

>
>Issues that immediately occur to me are:
>
>1) Another keyword
>2) How do you reference variables that aren't in the specified
>namespace without a second keyword!
>3) Issue 2 becomes critical when you what to deal with temporary
>results that you definately want discarded along with the current
>local scope.  So maybe only rvalues are affected ie.
>
>with self:
>    self.y = x**2 * t/z + a * FFT(tseries)
>
>might be better, but then the inconsistency bites.
>
>Maybe this is a good idea?  More likely I'm about to learn which
>critical basic flaw I've missed.
>
>at-least-I-will-get-to-learn-something-ly yours
>
>Andrae Muys



More information about the Python-list mailing list