Syntax for accessing old results/variables

Skip to first unread message

Guy Adini

Aug 30, 2012, 5:47:49 AM8/30/12
Hi everybody (turn out that there is an everybody :)),

I just read (highly recommended - it helped things click for me), and tried to think up some use cases of my own. 

One nice idea was to apply various image transformations to a list of images.

Here's one thing I tried to do:

In Python, the code would look like this (assuming that PIL is installed):

import Image
import ImageEnhance
import glob

for im_filename in glob.glob('*.jpg'):
    im =
    contrast_enhancer = ImageEnhance.Contrast(im)
    contrast_enhancer.enhance(1.3).save('contrast_' + im_filename)
    sharpness_enhancer = ImageEnhance.Sharpness(im)
    contrast_enhancer.enhance(2).save('sharpness_' + im_filename)

In Pythonect, we would be looking for something like this:

[glob.glob('*.jpg') ->] -> [ [color_enhance -> save to 'color' + orig_ filename], [contrast_enhance -> save to 'contrast' + orig_filename] ].

However, for the save function, we need the filename, which doesn't carry over through the creation of the enhancer.

Is there some way to access the result of an old calculation in Pythonect (like we use _ for the result of the last calculation, but for an older one)?

And if not - I have a feeling that this is something that we would like in the syntax. Maybe _[-2] for the second last calculaton, etc.

Itzik Kotler

Sep 2, 2012, 10:11:45 AM9/2/12
Excellent question. I don't know.

I have posted a RFC on the issue at:


I have generalized your suggestion (i.e. _[-2]) into a LIFO stack.

If you meant something else, feel free to clarify.

You received this message because you are subscribed to the Google Groups "pythonect" group.
To view this discussion on the web visit
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Guy Adini

Sep 2, 2012, 10:23:16 AM9/2/12
Aha - cool.

Will the LIFO stack be shared between multiple threads?
That is, will the following work:
glob.glob(*) -> push(_) -> open(_) -> -> _.replace('Zoom', 'Zuboom') -> open(pop(), 'w').write(_) 

Or will we have to replace the first '->' with '|' to maintain a proper call stack?


Itzik Kotler

Sep 2, 2012, 10:27:09 AM9/2/12
Can be. It's possible to make push() and pop() work with a global (across thread/processes) stack, and the _[-1], _[-2] syntax will be used for flow-specific stack.


Guy Adini

Sep 2, 2012, 10:38:19 AM9/2/12
First of all - sorry if I'm spamming too much.
But it's worth keeping in mind that my _[-1], _[-2] syntax is probably a bad idea:
it's ambiguous in the case that _ is a list/tuple.


Itzik Kotler

Sep 2, 2012, 10:47:22 AM9/2/12
Before you got here, it was a dead mailing list - now it's a low volume traffic mailing list :P

You are right, _[-1] is indeed be ambiguous. Can be replaced with _{1} or _<1> to keep the same notation/idea.

Also, I'm interested to know what you and the others are thinking re the other suggested implementations.



Sep 2, 2012, 7:58:47 PM9/2/12
I'm not sure about all this, IMO a predefined LIFO stack would only make the language more complex and add unnecessary syntactic sugar.
The programmer him/herself can easily create a list and use it to store and access old values.

Also, I think a list is more suitable for this purpose due to it's flexibility and "pythonic" nature.
Reply all
Reply to author
0 new messages