On Wed, 21 Sep 2005, Steven D'Aprano wrote: > On Mon, 19 Sep 2005 19:40:12 -0700, jbperez808 wrote: > >> Having to do an array.array('c',...): >> >> >>> x=array.array('c','ATCTGACGTC') >> >>> x[1:9:2]=array.array('c','AAAA') >> >>> x.tostring() >> 'AACAGACATC' >> >> is a bit klunkier than one would want, but I guess the efficient >> performance is the silver lining here. > > There are a number of ways to streamline that. The simplest is to merely > create an alias to array.array: > > from array import array as str > > Then you can say x = str('c', 'ATCTGACGTC'). > > A little more sophisticated would be to use currying: > > def str(value): > return array.array('c', value) > > x = str('ATCTGACGTC')
There's a special hell for people who override builtins. > although to be frank I'm not sure that something as simple as this > deserves to be dignified with the name currying. It's definitely not currying - it doesn't create a new function. Currying would be: def arraytype(kind): def mkarray(value): return array.array(kind, value) return mkarray chars = arraytype('c') seq = chars("tacatcgtcgacgtcgatcagtaccc") > Lastly, you could create a wrapper class that implements everything you > want. For a serious application, this is probably what you want to do > anyway: Definitely - there are lots of things to know about DNA molecules or parts of them that aren't captured by the sequence. tom -- If it ain't Alberta, it ain't beef. -- http://mail.python.org/mailman/listinfo/python-list