Syntax for accessing old results/variables

17 views
Skip to first unread message

Guy Adini

unread,
Aug 30, 2012, 5:47:49 AM8/30/12
to pyth...@googlegroups.com
Hi everybody (turn out that there is an everybody :)),

I just read http://blog.ikotler.org/2012/08/automated-static-malware-analysis-with.html (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 = Image.open(im_filename)
    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') -> Image.open(_)] -> [ [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

unread,
Sep 2, 2012, 10:11:45 AM9/2/12
to pyth...@googlegroups.com
Excellent question. I don't know.

I have posted a RFC on the issue at: https://groups.google.com/d/topic/pythonect/xSnBhmLXXwg/discussion


P.S.

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 https://groups.google.com/d/msg/pythonect/-/gKGe4u98fl0J.
To post to this group, send email to pyth...@googlegroups.com.
To unsubscribe from this group, send email to pythonect+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pythonect?hl=en.

Guy Adini

unread,
Sep 2, 2012, 10:23:16 AM9/2/12
to pyth...@googlegroups.com
Aha - cool.

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

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

--
 
 

Itzik Kotler

unread,
Sep 2, 2012, 10:27:09 AM9/2/12
to pyth...@googlegroups.com
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

unread,
Sep 2, 2012, 10:38:19 AM9/2/12
to pyth...@googlegroups.com
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

unread,
Sep 2, 2012, 10:47:22 AM9/2/12
to pyth...@googlegroups.com
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.

--
 
 

TL

unread,
Sep 2, 2012, 7:58:47 PM9/2/12
to pyth...@googlegroups.com
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
Forward
0 new messages