Re: matplotlib
[EMAIL PROTECTED] wrote: > This site and webpage in particular doesn't open. I tried that too > before posting my question. > There seems to be a nice cookbook: http://www.scipy.org/Cookbook/Matplotlib Jakub -- http://mail.python.org/mailman/listinfo/python-list
Re: fail to indent in inner loop
[EMAIL PROTECTED] wrote: > hi > > I've started learning python. I was typing from a tutorial, > and I fail to indent on an inner loop. > I got an error and all my previous typed lines are gone. > is there a way to prevent this. > i don't mind editing the last line, but to lose all the previous lines > are too much. > (since it has history function like bash.) > Try using PyCrust. Using PyCrust is very instructive (for example, you can see the namespace tree) and Alt+P history returns the whole previous block of code. Jakub -- http://mail.python.org/mailman/listinfo/python-list
Strange behavior of __get__ in a descriptor in IPython
Hi, I'm studying the descriptor protocol and its usage from the following document: http://users.rcn.com/python/download/Descriptor.htm There is some sample code: http://users.rcn.com/python/download/Descriptor.htm#descriptor-example that behaves in a different way on my machine than the example suggests: In [2]: a=MyClass() In [3]: a.x Retrieving var "x" Retrieving var "x" Out[3]: 1 On the other hand, in the 'plain' Python shell, it's invoked only once as expected: >>> a=desc.MyClass() >>> a.x Retrieving var "x" 10 >>> Should I take as granted that IPython might in some cases access an attribute of an object more than once even in face of side effects, or is this a bug? Regards, Jakub Hegenbart -- http://mail.python.org/mailman/listinfo/python-list
Re: Confused about closures and scoping rules
On Wed, 07 Nov 2007 01:37:00 +0100, Chris Mellon <[EMAIL PROTECTED]> wrote: > Are there languages where closures *don't* behave like this? A closure > that used a copy of the state rather than the actual state itself > doesn't seem as useful. For references sake, JavaScript (the only > language that a) has closures and b) I have a handy way to test with) > does the same thing. The results in an equivalent code might depend on the semantics of the looping construct used. For example, take Scheme (I'm using Gauche Scheme): (define (outer-1 nmax) (let ((aa '())) (dotimes (n nmax) (push! aa (lambda (y) (list "y:" y "n:" n aa)) (define (outer-2 nmax) (let ((aa '()) (n 0)) (until (= n nmax) (push! aa (lambda (y) (list "y:" y "n:" n))) (set! n (+ n 1))) aa)) (print (map (lambda (f) (f 1)) (outer-1 5))) (print (map (lambda (f) (f 1)) (outer-2 5))) $ gosh closures.scm ((y: 1 n: 4) (y: 1 n: 3) (y: 1 n: 2) (y: 1 n: 1) (y: 1 n: 0)) ((y: 1 n: 5) (y: 1 n: 5) (y: 1 n: 5) (y: 1 n: 5) (y: 1 n: 5)) In outer-1, the (dotimes ...) form expands into (do ...). R5RS defines that a (do ...) loop is expected to _rebound_ all of its state variables (here it is only n) in each iteration step. This means that each closure created captures a different binding. Whereas in outer-2, I am updating the binding destructively, so the value changes in the environment of all the closures that have been already stored. Python seems to do the latter. (I am not a pythonist right now, but I am learning... :)) Regards, Jakub -- http://mail.python.org/mailman/listinfo/python-list