Is this a bug?

2013-07-15 Thread Jack Bates
Hello, Is the following code supposed to be an UnboundLocalError? Currently it assigns the value 'bar' to the attribute baz.foo foo = 'bar' class baz: foo = foo -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this a bug?

2013-07-16 Thread Jack Bates
On 15/07/13 09:13 AM, Joshua Landau wrote: On 15 July 2013 16:50, Jack Bates wrote: Hello, Is the following code supposed to be an UnboundLocalError? Currently it assigns the value 'bar' to the attribute baz.foo foo = 'bar' class baz: foo = foo If so,

Identical descriptor value, without leaking memory?

2011-07-29 Thread Jack Bates
How can you get a descriptor to return an identical value, each time it's called with the same "instance" - without leaking memory? #!/usr/bin/env python class descriptor: class __metaclass__(type): def __get__(self, instance, owner): ... class owner: descriptor = descriptor inst

Replace all references to one object with references to other

2011-08-05 Thread Jack Bates
I have two objects, and I want to replace all references to the first object - everywhere - with references to the second object. What can I try? -- http://mail.python.org/mailman/listinfo/python-list

Measure the amount of memory used?

2011-08-18 Thread Jack Bates
I wrote a content filter for Postfix with Python, https://github.com/jablko/cookie It should get started once, and hopefully run for a long time - so I'm interested in how it uses memory: 1) How does the amount of memory used change as it runs? 2) How does the amount of memory used change as I

Reliably call code after object no longer exists or is "unreachable"?

2011-04-27 Thread Jack Bates
In Python, how can you reliably call code - but wait until an object no longer exists or is "unreachable"? I want to ensure that some code is called (excluding some exotic situations like when the program is killed by a signal not handled by Python) but can't call it immediately. I want to wait un

"raise (type, value, traceback)" and "raise type, value, traceback"

2011-05-02 Thread Jack Bates
Hi, anyone know why these two statements aren't equivalent? raise (type, value, traceback) raise type, value, traceback -- http://mail.python.org/mailman/listinfo/python-list

Pair of filenos read/write each other?

2013-08-13 Thread Jack Bates
Can anyone suggest a way to get a pair of file descriptor numbers such that data written to one can be read from the other and vice versa? Is there anything like os.pipe() where you can read/write both ends? Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: Pair of filenos read/write each other?

2013-08-15 Thread Jack Bates
On Wed, Aug 14, 2013 at 01:17:40AM +0100, Rhodri James wrote: > On Wed, 14 Aug 2013 00:10:41 +0100, Jack Bates > wrote: > > > Can anyone suggest a way to get a pair of file descriptor numbers such > > that data written to one can be read from the other and vice ve

Re: Pair of filenos read/write each other?

2013-08-15 Thread Jack Bates
On Wed, Aug 14, 2013 at 01:55:38AM +0100, Chris Angelico wrote: > On Wed, Aug 14, 2013 at 1:17 AM, Rhodri James > wrote: > > On Wed, 14 Aug 2013 00:10:41 +0100, Jack Bates > > wrote: > > > >> Can anyone suggest a way to get a pair of file descriptor numbers such

Re: Pair of filenos read/write each other?

2013-08-15 Thread Jack Bates
On Wed, Aug 14, 2013 at 08:34:36AM +, Antoine Pitrou wrote: > Nobody nowhere.com> writes: > > On Tue, 13 Aug 2013 16:10:41 -0700, Jack Bates wrote: > > > Is there anything like os.pipe() where you can read/write both ends? > > > > There's socket.socketp

buffer() as argument to ctypes function which expects c_void_p?

2011-09-08 Thread Jack Bates
How do you pass a Python buffer() value as an argument to a ctypes function, which expects a c_void_p argument? I keep getting TypeError: ctypes.ArgumentError: argument 2: : wrong type -- http://mail.python.org/mailman/listinfo/python-list

ImportError: cannot import name dns

2011-09-13 Thread Jack Bates
Why is the following ImportError raised? $ ./test Traceback (most recent call last): File "./test", line 3, in from foo import dns File "/home/jablko/foo/dns.py", line 1, in from foo import udp File "/home/jablko/foo/udp.py", line 1, in from foo import dns ImportError: cannot

Re: ImportError: cannot import name dns

2011-09-14 Thread Jack Bates
> It is a circular dependency. Dns will try to import udp which will in turn > import dns (again) in an endless cycle; instead an ImportError is raised. > > Circular dependency is a Bad Thing. According to this documentation: http://docs.python.org/reference/simple_stmts.html#grammar-token-impor

method-to-instance binding, callable generator decorator

2011-01-26 Thread Jack Bates
Am struggling to understand Python method-to-instance binding Anyone know why this example throws a TypeError? > #!/usr/bin/env python > > import functools > > # Take a generator function (i.e. a callable which returns a generator) and > # return a callable which calls .send() > class coroutine