Sequence splitting

2009-07-02 Thread schickb
I have fairly often found the need to split a sequence into two groups based on a function result. Much like the existing filter function, but returning a tuple of true, false sequences. In Python, something like: def split(seq, func=None): if func is None: func = bool t, f = [], [

Re: new.instancemethod questions

2009-01-29 Thread schickb
On Jan 29, 8:51 pm, Brian Allen Vanderburg II wrote: > You can also create a bound method and manually bind it to the > instance.  This is easier > > import types > a.f2 = types.MethodType(f1, a) > > a.f2() # prints object a Ah thanks, that is what I was looking for. I missed that because followi

Re: new.instancemethod questions

2009-01-29 Thread schickb
On Jan 29, 7:38 pm, Mel wrote: > schickb wrote: > > I'd like to add bound functions to instances, and found the > > instancemethod function in the new module. A few questions: > > > 1. Why is instancemethod even needed? Its counter-intuitive (to me at > > le

new.instancemethod questions

2009-01-29 Thread schickb
I'd like to add bound functions to instances, and found the instancemethod function in the new module. A few questions: 1. Why is instancemethod even needed? Its counter-intuitive (to me at least) that assigning a function to a class results in bound functions its instances, while assigning direct

Regex for unicode letter characters

2009-01-10 Thread schickb
I need a regex that will match strings containing only unicode letter characters (not including numeric or the _ character). I was surprised to find the 're' module does not include a special character class for this already (python 2.6). Or did I miss something? It seems like this would be a very

Re: Sequence iterators with __index__

2008-06-25 Thread schickb
On Jun 25, 12:11 am, schickb <[EMAIL PROTECTED]> wrote: > > But this isn't just about slicing. I'd like sequence iterators to be > usable as simple indexes as well; like a[it] (which __index__ would > also provide). It occurred to me that this wouldn't need to

Re: Sequence iterators with __index__

2008-06-25 Thread schickb
On Jun 24, 5:46 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > > Wanting to slice while iterating is a *very* specialized usage. I disagree because iterators mark positions, which for sequences are just offsets. And slicing is all about offsets. Here is a quote from the already implemented PEP 357:

Re: Sequence iterators with __index__

2008-06-24 Thread schickb
On Jun 24, 3:45 pm, Matimus <[EMAIL PROTECTED]> wrote: > > > I think it would be useful if iterators on sequences had the __index__ > > method so that they could be used to slice sequences. I was writing a > > class and wanted to return a list iterator to callers.  I then wanted > > to let callers

Sequence iterators with __index__

2008-06-24 Thread schickb
I think it would be useful if iterators on sequences had the __index__ method so that they could be used to slice sequences. I was writing a class and wanted to return a list iterator to callers. I then wanted to let callers slice from an iterator's position, but that isn't supported without creat

Re: Popen pipe hang

2008-05-12 Thread schickb
On May 12, 7:35 pm, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > >from subprocess import Popen, PIPE > >from array import array > > >arr = array('B') > >arr.fromstring("hello\n") > > >src = Popen( ["cat"], stdin=PIPE, stdout=PIPE) > >dst = Popen( ["cat"], stdin=src.stdout) > >arr.tofile(src.std

Popen pipe hang

2008-05-12 Thread schickb
I'm trying to pipe data that starts life in an array('B') object through several processes. The code below is a simplified example. The data makes it through, but the wait() always hangs. Is there a better way to indicate src.stdin has reach EOF? from subprocess import Popen, PIPE from array impor