Re: Help understanding the decisions *behind* python?

2009-07-24 Thread Beni Cherniavsky
On Jul 22, 9:36 am, Hendrik van Rooyen wrote: > On Tuesday 21 July 2009 15:49:59 Inky 788 wrote: > > > My guess is that it was probably for optimization reasons long ago. > > I've never heard a *good* reason why Python needs both. > > The good reason is the immutability, which lets you use > a tup

Re: It's ...

2009-06-30 Thread Beni Cherniavsky
On Jun 24, 11:40 pm, "J. Cliff Dyer" wrote: > Also note that you can iterate over a file several times: > > f = open('foo.txt') > for line in f: > print line[0] # prints the first character of every line > for line in f: > print line[1] #prints the second character of every line > No, yo

Re: Optimizing math functions

2009-05-31 Thread Beni Cherniavsky
On May 31, 12:41 pm, Beni Cherniavsky wrote: > > Take a look athttp://openopt.org(python-scikits-openopt on debian/ > ubuntu) - a lot of optimization engines under one interface, so you > can try different engines easily and without learning many interfaces. > Correction: don&#

Re: Optimizing math functions

2009-05-31 Thread Beni Cherniavsky
On May 23, 4:22 pm, Esmail wrote: > > Is there some sort of simple Python module that would allow me to > evaluate this type of function? > > In this particular instance I am interested in the minimum of > >    x * sin(4*x) + 1.1 * sin(2*y), where x,y in range 0-10 > > though in other problems the

Re: What's the use of the else in try/except/else?

2009-05-17 Thread Beni Cherniavsky
[Long mail. You may skip to the last paragraph to get the summary.] On May 12, 12:35 pm, Steven D'Aprano wrote: > To really be safe, that should become: > > try: >     rsrc = get(resource) > except ResourceError: >     log('no more resources available') >     raise > else: >     try: >         do

Re: Best practice for operations on streams of text

2009-05-17 Thread Beni Cherniavsky
On May 8, 12:07 am, MRAB wrote: > def compound_filter(token_stream): >      stream = lowercase_token(token_stream) >      stream = remove_boring(stream) >      stream = remove_dupes(stream) >      for t in stream(t): >          yield t The last loop is superfluous. You can just do:: def compoun

Re: Introducing Python to others

2009-03-28 Thread Beni Cherniavsky
Small additions: On Mar 26, 7:35 pm, "J. Cliff Dyer" wrote: > > 2) Aliasing imports is also cool.  Show people how easy it is to switch > from > > >>> import MySQLdb as db > to > >>> import psycopg2 as db > > and have all your dbapi2 code still work.  Or from > > >>> from StringIO import StringIO

Re: Special keyword argument lambda syntax

2009-03-14 Thread Beni Cherniavsky
On Mar 14, 5:30 pm, Nick Craig-Wood wrote: > BeniCherniavsky wrote: > >  This proposal outrageously suggests a special syntax for in-line > >  functions passed as keyword arguments:: > > >      >>> sorted(range(9), key(n)=n%3) > >      [0, 3, 6, 1, 4, 7, 2, 5, 8] > > >  The claim is that such spec

Special keyword argument lambda syntax

2009-03-13 Thread Beni Cherniavsky
This proposal (a) ignores Guido's clear-cut decision that lambda is good as it is, (b) is weird in proposing a special-case syntax, (c) is several Python versions too late for a graceful transition by 3.0. But I don't won't to just throw the idea away, so I'm posting here. If there is serious posit

Where is the ucs-32 codec?

2006-06-04 Thread beni . cherniavsky
#x27;-le' and '-be' variats, I suppose. Should there be a variant without explicit endianity, using a BOM to decide (like 'utf-16')? And it should combine surrogates into valid characters (on all builds), like the 'utf-8' codec does, right? -- Beni Cherniavsky &l

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread Beni Cherniavsky
Alexander Schmolck wrote: "Raymond Hettinger" <[EMAIL PROTECTED]> writes: The rationale is to replace the awkward and slow existing idioms for dictionary based accumulation: d[key] = d.get(key, 0) + qty d.setdefault(key, []).extend(values) Indeed not too readable. The try..except version is