Last comments
In response to: Ubuntu joke
Rama [Visitor]
Check this out: http://ubuntulinuxhelp.com/can-we-talk-here/ It's very heartfelt and compassionate; and really does say what Ubuntu really is about.
Permalink 02/24/08 @ 18:35
In response to: Python strangeness
Sylvain Defresne [Visitor]
In Python, closure capture the current frame (a reference to it in fact), not the current binding. So in when you define the local _f function, the current frame is captured, and when it is called, the local variable l is searched in this frame, and since the frame is not copied, but merely referenced, the value is the last value bound to the name l in the frame.
A simple example :
If you want to capture the current value, you need to change your function to take an additional parameter with a default value initialized with l[0], as default value of parameter are evaluated when compiling the function.
Your code should be changed to (only including the function declaration) :
A simple example :
>>> def test():
... def f():
... print i
... i = 4
... f()
... i = 5
... f()
...
>>> test()
4
5
If you want to capture the current value, you need to change your function to take an additional parameter with a default value initialized with l[0], as default value of parameter are evaluated when compiling the function.
Your code should be changed to (only including the function declaration) :
>>> for l in list:
... if not hasattr(Klass, l[1]):
... print '%s should print %d' % (l[1], l[0])
... def _f(self, v = l[0]):
... print v
... _f.__doc__ = 'Get %s' % l[1]
... setattr(Klass, l[1], _f)
Permalink 12/14/07 @ 08:13
In response to: Python strangeness
James Henstridge [Visitor] · http://blogs.gnome.org/jamesh/
One thing you need to remember is that the nested function _f is not storing a reference to "l" from the parent scope: it has a reference to the parent scope itself. So when you rebind "l" in the parent scope, it affects what _f() sees.
There are a few solutions to the problem:
1. bind "l" as a default value to an argument of _f().
2. define _f() in a scope where "l" does not change (i.e. call another function that creates _f() inside your loop).
3. Go the object oriented route, and use an instance rather than a function. By making use of the descriptor __get__() call, you can do method-style binding to instances.
There are a few solutions to the problem:
1. bind "l" as a default value to an argument of _f().
2. define _f() in a scope where "l" does not change (i.e. call another function that creates _f() inside your loop).
3. Go the object oriented route, and use an instance rather than a function. By making use of the descriptor __get__() call, you can do method-style binding to instances.
Permalink 12/14/07 @ 04:25
In response to: Python strangeness
ignacio [Visitor]
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/502271
Permalink 12/14/07 @ 04:04
In response to: Python strangeness
Ikke [Member] · http://www.eikke.com
Here's how I was thinking: "list" is an array of pointers to some "tupple" structure. I iterate through all these pointers, and assign the location of the current tupple to "l". Then I generate some function, _f, which uses the object at location given by l. If later on I change l (so it points to something else), the memory location used into the previously defined function should not change *with* l... It's like
char *foo = "bar";
char *baz = foo;
foo = "bat";
printf("%s %s\n", foo, baz);
which prints "bat bar", not "bat bat".
I know about the "list" name, stupid, wouldn't do that in production code :-)
char *foo = "bar";
char *baz = foo;
foo = "bat";
printf("%s %s\n", foo, baz);
which prints "bat bar", not "bat bat".
I know about the "list" name, stupid, wouldn't do that in production code :-)
Permalink 12/14/07 @ 03:08
In response to: Python strangeness
Anonymous [Visitor]
(Note: the code in this comment uses > for indentation, because you don't allow the pre tag.)
The problem comes when you define the function _f. Your definition references l by reference, not by value. Your loop changes l.
This way of binding variables from outer scopes provides a lot of power; for example, you can define a callback function that references variables from your outer scope directly, rather than needing a magic "caller context" argument as you might find in C.
To do what you want, try this:
Alternatively, reference the original tuple item, which won't change:
As an aside, don't call your lists
has a built-in function named
The problem comes when you define the function _f. Your definition references l by reference, not by value. Your loop changes l.
This way of binding variables from outer scopes provides a lot of power; for example, you can define a callback function that references variables from your outer scope directly, rather than needing a magic "caller context" argument as you might find in C.
To do what you want, try this:
def make_print(v, doc):
>def _f():
>>print v
>_f.__doc__ = doc
>return f
for l in list:
>if not hasattr(Klass, l[1]):
>>print '%s should print %d' % (l[1], l[0])
>>setattr(Klass, l[1], make_print(l[0], 'Get %s' % l[1]))
Alternatively, reference the original tuple item, which won't change:
for i in enumerate(list):
>if not hasattr(Klass, list[i][1]):
>>print '%s should print %d' % (list[i][1], list[i][0])
>>def _f(self):
>>>print list[i][0]
>>_f.__doc__ = 'Get %s' % list[i][1]
>>setattr(Klass, list[i][1], _f)
As an aside, don't call your lists
list
, because Pythonhas a built-in function named
list
. Worse yet, don't call your tuples list
. :)
Permalink 12/14/07 @ 02:50
In response to: Seam Carving: Content-aware image resizing
hou k [Visitor]
I am very interested in this algorithm. Could you send me a copy of the source code? Thanks a lot.
Permalink 12/13/07 @ 09:12
In response to: Seam Carving: Content-aware image resizing
Lazar [Visitor] · http://www.inverudio.com
I was gonna ask you about source code, but then I read comments...
Permalink 11/26/07 @ 01:30
In response to: Seam Carving: Content-aware image resizing
yaniv [Visitor] · http://yaniv.leviathanonline.com
Cool post.
I also have a python implementation (many people posted interesting ideas on my post).
I also have a python implementation (many people posted interesting ideas on my post).
Permalink 11/23/07 @ 17:07
In response to: New prototype
jg [Visitor]
Is there a way to allow the softphone to pop when the screen saver has kicked in?
without having to enter the unlock credentials?
without having to enter the unlock credentials?
Permalink 11/09/07 @ 22:31
In response to: Clutter, advanced UI graphics made fun
Dave Foster [Visitor]
Yeah, it's cool. I've just updated my clutter build and will try to do some examples when I get home. I can't run glx stuff over vnc :)
Permalink 11/08/07 @ 17:47
In response to: Clutter, advanced UI graphics made fun
Ikke [Member] · http://www.eikke.com
I repeat: I know this is nothing really "new", it's just a playground.
Oh and, my antispamsystem dislikes blogspot.
Oh and, my antispamsystem dislikes blogspot.
Permalink 11/08/07 @ 17:29
In response to: Clutter, advanced UI graphics made fun
Dave Foster [Visitor]
Certainly not to rain on anything here but someone in the gnome world has done something similar:
njpatel dot blogspot dot com/2007/06/flickr-clutter-fluttr.html
(it won't let me submit that in link form!)
Clutter looks increasingly cool, and I plan on looking at your implementation here to find out how to use it a bit better. It seems to be in a constant flux though, so I'm not sure learning it now would really be useful.
njpatel dot blogspot dot com/2007/06/flickr-clutter-fluttr.html
(it won't let me submit that in link form!)
Clutter looks increasingly cool, and I plan on looking at your implementation here to find out how to use it a bit better. It seems to be in a constant flux though, so I'm not sure learning it now would really be useful.
Permalink 11/08/07 @ 16:13
In response to: Clutter, advanced UI graphics made fun
Ikke [Member] · http://www.eikke.com
Matt: glad it's useful to at least someone :-)
Corey: IIRC lowfat is written using more low-level OpenGL, which I don't know (yet). I did not intend to write a full-fledged slideshow app whatsoever, actually the main reason I started to look at Clutter was to write some (non-interactive) "public information display", easy to manage for non-geeks, software.
Corey: IIRC lowfat is written using more low-level OpenGL, which I don't know (yet). I did not intend to write a full-fledged slideshow app whatsoever, actually the main reason I started to look at Clutter was to write some (non-interactive) "public information display", easy to manage for non-geeks, software.
Permalink 11/08/07 @ 10:55
In response to: More messaging
Ikke [Member] · http://www.eikke.com
Err, not really... Doing the "wall" thing didn't work out, so I gave up.
Permalink 11/08/07 @ 10:50
In response to: Clutter, advanced UI graphics made fun
Corey Burger [Visitor]
You should take a look at Macslow's lowfat. It needs work and having combined effort would actually produce something faster!
Permalink 11/08/07 @ 07:19
In response to: Clutter, advanced UI graphics made fun
Matt [Visitor]
Thanks man. I am sort of dabbling in learning C/C++ (mainly out of curiosity), this has been a big help with clutter. Cheers.
Permalink 11/08/07 @ 05:45
In response to: More messaging
Cody Harris [Visitor] · http://blog.vectec.net
Any progress on this? I've been trying to do this myself, but I can't figure it out.
Permalink 11/08/07 @ 04:21
In response to: Being a Certificate Authority made easier than ever
Ikke [Member] · http://www.eikke.com
I know the TinyCA package, but it's not suited for this scenario as we work using an console-only server, and don't want to have our CA key anywhere outside it.
Permalink 10/29/07 @ 13:10
In response to: Being a Certificate Authority made easier than ever
Willem Dantuma [Visitor]
Have you ever tried TinyCA for this ?, it is a Perl/GTK interface for openssl. I use it to manage my certificates.
Permalink 10/29/07 @ 13:06