Re: Why are there no ordered dictionaries?

2005-11-26 Thread Bengt Richter
On Thu, 24 Nov 2005 18:42:45 +0100, Christoph Zwerschke <[EMAIL PROTECTED]> wrote: >Bengt Richter schrieb: > >>>d.setvalues((13, 14)) ==> d = OrderedDict((1, 13), (2, 14)) > >> The implication above is that OrderedDict takes an *args argument, >> but real

Re: Why are there no ordered dictionaries?

2005-11-26 Thread Bengt Richter
On Fri, 25 Nov 2005 19:42:49 +, Tom Anderson <[EMAIL PROTECTED]> wrote: >On Wed, 23 Nov 2005, Carsten Haese wrote: > >> On Wed, 2005-11-23 at 15:17, Christoph Zwerschke wrote: >>> Bengt Richter wrote: >>> >>> > E.g., it might be nice to have

Re: Whitespace test after string.split

2005-11-26 Thread Bengt Richter
'delta'] > >There you are. Alternatively, possibly >>> [t for t in (t.strip() for t in s.split(",")) if t] ['alpha', 'gamma', 'delta'] > >> As a second question, I am seeing string split as deprecated in 2.4.2 >> manual. What is planned in future to split (strings or unicode)? > >Just use the corresponding methods, e. g. s.strip() instead of >string.strip(s) etc. > >Peter > Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: General question about Python design goals

2005-11-28 Thread Bengt Richter
maybe the docs maintainers are accomodating, but I'd be the average reader wouldn't have a concept of how a "patch" should be prepared. I know the info is not far away in the python.org site but still, is there an interface that will bring up a doc page in a browser and let yo

Re: Death to tuples!

2005-11-29 Thread Bengt Richter
(BTW, matching length, necessarily? Or just long enough?) iterable in place of a tuple, just like it can take an arbitrary mapping object in place of a dict for e.g. '%(name)s'% {'name':''} Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Death to tuples!

2005-11-29 Thread Bengt Richter
and return what a normal property would. Plain functions in foomod.__classvars__ would return bound methods with foomod in "self" position, so you could call graphics.draw(args) and know that draw if so designed could be defined as def draw(mod, *args): ... Just another idea ;-) [1] actually, during a function call, the frame instance if probably more like the "self", but let's say the name resolution order for local access extends to foo.__classvars__ somethow as if that were an overriding front end base class dict of the mro chain. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Precision for equality of two floats?

2005-11-29 Thread Bengt Richter
ues on the cpu stack, not the fpu stack, I assume it's ok there, but is it a potential problem for optimizers generating machine code? Or is it spec-ed for mandatory as-if-storing-both-arguments-as-double-before-comparing behaviour? Just wondering ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: General question about Python design goals

2005-11-29 Thread Bengt Richter
On Tue, 29 Nov 2005 00:52:25 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] (Bengt Richter) writes: >>>Then feel free to submit patches for the docs. >> This is easy to say, and maybe the docs maintainers are accomodating, >> but I'd be the ave

Re: General question about Python design goals

2005-11-29 Thread Bengt Richter
likely we will get helpful solution ideas for a menu of choices, and avoid prematurely discussing whether we should have pumpkin pie with or without whipped cream, when finally we might all like strawberries and cream better, if someone had thought of it. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Death to tuples!

2005-11-29 Thread Bengt Richter
On Tue, 29 Nov 2005 09:26:53 -0600, [EMAIL PROTECTED] wrote: > >--cvVnyQ+4j833TQvp >Content-Type: text/plain; charset=us-ascii >Content-Disposition: inline > >On Tue, Nov 29, 2005 at 10:41:13AM +0000, Bengt Richter wrote: >> Seems like str.__mod__ could take an arbita

Re: Why are there no ordered dictionaries?

2005-11-29 Thread Bengt Richter
On Sun, 27 Nov 2005 12:00:23 +0100, Christoph Zwerschke <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >>>d.keys[:] = newkeyseq >> >> Do you really mean just re-ordering the keys without a corresponding >> reording of values?? >> That would

Re: Why are there no ordered dictionaries?

2005-11-29 Thread Bengt Richter
need to mod the original. Where next? This ordered dict thing is kind of a side-track from a side-track for me ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Computer Language Shootout

2005-11-29 Thread Bengt Richter
e how top-posting screws things up? The immediately above is what you responded to. Your response and mine (which is in parts interpolated into yours below parts of yours the put relevant response below what it is responding to) all belong down here. Double-pfui. I better eat. I note that I was

Re: Computer Language Shootout

2005-11-29 Thread Bengt Richter
On 29 Nov 2005 18:34:34 -0800, [EMAIL PROTECTED] wrote: > >Bengt Richter wrote: >> On 29 Nov 2005 14:08:12 -0800, [EMAIL PROTECTED] wrote: >> >> >We don't scrape programs from news-groups, if you'd like the program to >> >be shown on the sh

Re: newbie question concerning formatted output

2005-11-29 Thread Bengt Richter
() for line in StringIO("""\ ... 3905 ... 3009 ... ... 4508 ... f504 ... ... 3707 ... 5a07 ... ... """)) >>> import itertools >>> for k,g in itertools.groupby(ins, lambda _, c=itertools.count().next: >>> c()//3): ... print '%s %s %s' % tuple(g) ... 3905 3009 4508 f504 3707 5a07 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie question concerning formatted output

2005-11-29 Thread Bengt Richter
27;%open('xyplan.nobreaks').read() 3905 3009 4508 f504 3707 5a07 Now the one-liner, FWIW ;-) >>> print '\n'.join(' '.join(z) for it in [(ln.strip() for ln in >>> open('xyplan.nobreaks'))] for z in (zip(it, it, it) )) 3905 3009 4508 f504 3707 5a07 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Nested loop

2005-11-30 Thread Bengt Richter
fSymbol.strip() for refSymbol in symbols) for showme in (lookupSymbol.split('\t') for lookupSymbol in myfile): if showme[3] in refSymbolSet: priceNew.write(showme[3]+" "+showme[10]) It would probably be more robust to check for blank lines and showme missing fields and symbol duplicates also. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to list currently defined classes, methods etc

2005-11-30 Thread Bengt Richter
>> help(__name__) might be interesting for the OP too ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-12-01 Thread Bengt Richter
__ Only d.values() ? tests finished: 17 passed, 11 failed in 1.36 seconds = [1] I changed the tests to use a CandidateDict alias, and eliminated a couple of checks on internal state, so as to allow differen

Re: Why are there no ordered dictionaries?

2005-12-01 Thread Bengt Richter
s to usage patterns 1) how many instances created, deleted 2) how many elements in an instance min, max? 3) how often updated? 3a) just ordering, no value or size change? 3b) just value change, no order or size change? 3c) changes involving size? 4) proportions of read vs write/dele

Re: Death to tuples!

2005-12-01 Thread Bengt Richter
their values. > >This would be no more surprising than a variable referenced in a normal >expression to have changed values between two evaluations. Sure, you could have it work that way, but would it really be useful? Is this a matter of thinking up some sugar for def foo(arg=None) if arg is None: arg = [] or what are we pursuing? Hm, I was just going to say it might be nice to have a builtin standard sentinel, or a convention for using something as such. I don't really like manufacturing sentinel=object() when I need something other than None. So it just occurred to me maybe def foo(arg=NotImplemented) if arg is NotImplemented: arg = [] maybe SENTINEL could be defined similarly as a builtin constant. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-01 Thread Bengt Richter
On Wed, 30 Nov 2005 20:53:50 -0500, [EMAIL PROTECTED] wrote: >Please trim replies... ; ) > Not quite so far ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: New Ordered Dictionery to Criticise

2005-12-01 Thread Bengt Richter
not in (None, 1) I seemed a bit too weird. But I guess I could just let the programmer decide ;-) > >d >{2: 9, 4: 8} > >""" >Because of the key collisions the length of > d has changed - it now only has two keys instead >of four. >""" IMO the above collision is an error that should raise an exception, because the collision is with a key outside the (albeit interlaced) target slice, so you are effectively assigning outside the slice. BTW, what about slices of keys and values? E.g. does d.keys[:] = ['prefix_'+ key for key in d.keys()] make sense? Note that it is different from d[:] = something. Similarly d.values, thoug d.items[sliceinst] might be the same as d[sliceinst] for assignment. d[sliceinst] returns an ordered dict though, where as d.items[sliceinst] returns the same item list slice as d.items()[sliceinst]. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: [[x,f(x)] for x in list that maximizes f(x)] <--newbie help

2005-12-02 Thread Bengt Richter
;>> [f(x) for x in mylist] [-15, -6, 1, 6, 9, 10, 9, 6, 1, -6] Then one line should do it: >>> max((f(x),x) for x in mylist) (10, 5) Ok, be picky ;-) >>> pair = list(reversed(max((f(x),x) for x in mylist))) >>> pair [5, 10] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Death to tuples!

2005-12-02 Thread Bengt Richter
On 2 Dec 2005 13:05:43 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote: >On 2005-12-02, Bengt Richter <[EMAIL PROTECTED]> wrote: >> On 1 Dec 2005 09:24:30 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote: >> >>>On 2005-11-30, Duncan Booth <[EMAI

Re: advice : how do you iterate with an acc ?

2005-12-02 Thread Bengt Richter
; should select those. Groupby won't return an empty group AFAIK, so you don't need to test for that. Also, you won't need the list call in list(acciter) if your dosomething can accept an iterator instead of a list. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: advice : how do you iterate with an acc ?

2005-12-03 Thread Bengt Richter
On 2 Dec 2005 18:34:12 -0800, [EMAIL PROTECTED] wrote: > >Bengt Richter wrote: >> It looks to me like itertools.groupby could get you close to what you want, >> e.g., (untested) >Ah, groupby. The generic string.split() equivalent. But the doc said >the input needs t

Re: os.rename copies when old is in-use - is this deliberate?

2005-12-03 Thread Bengt Richter
me1 filename2. Note that you cannot specify a new drive or path for your destination file. [ 3:26] C:\pywk\grammar>py24 Python 2.4b1 (#56, Nov 3 2004, 01:47:27) [GCC 3.2.3 (mingw special 20030504-1)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> help(os.rename) Help on built-in function rename in module nt: rename(...) rename(old, new) Rename a file or directory. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: advice : how do you iterate with an acc ?

2005-12-03 Thread Bengt Richter
On 3 Dec 2005 03:28:19 -0800, [EMAIL PROTECTED] wrote: > >Bengt Richter wrote: >> On 2 Dec 2005 18:34:12 -0800, [EMAIL PROTECTED] wrote: >> >> > >> >Bengt Richter wrote: >> >> It looks to me like itertools.groupby could get you close to what you &g

Re: Checking length of each argument - seems like I'm fighting Python

2005-12-03 Thread Bengt Richter
a passed vector x were scalars, you could write (untested) assert sum(isinstance(_, scalartype) for _ in x)==len(x) since True==1 as a subtype of integer. >>> sum(isinstance(_, scalartype) for _ in [1, 2.0, 3L]) 3 >>> sum(isinstance(_, scalartype) for _ in [1, 2.0, 3j]) 2 >>> sum(isinstance(_, scalartype) for _ in [1, 2.0, []]) 2 compared == len(thething) should work Of course, your next step in using vectors might give you the check for free, so no need for redundant checking. It's generally faster to let your args try to quack like the ducks you need, if possible and safe. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to execute an EXE via os.system() with spaces in the directory name?

2005-12-03 Thread Bengt Richter
and see it? What do you get for os.popen(CMD2).read() ? What do you get if you make a cmd file like echoargs.cmd below [23:29] C:\pywk\grammar>type c:\util\echoargs.cmd @echo %* and substitute echoargs (with path if necessary) in place of your executable in CMD2? Just suggestions to get more symptoms for diagnosis. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Most SHAMEFUL one-liner:

2005-12-04 Thread Bengt Richter
in range(yoffset - 2)] > >...and then I went on to do: > >"".join(fill) > >Talk about using the wrong tool for the job... :( > >All I needed was: > >" " * (columns - 1) * (yoffset - 2) > So the original was wrong as well as a bit opaque? (What ha

Re: what's wrong with "lambda x : print x/60,x%60"

2005-12-05 Thread Bengt Richter
e one >> at that. > >Of course. > If you think lambda is restrictive, you can use dumbda: >>> def dumbda(src): ... d = {} ... exec src in d ... for k,v in d.items(): ... if callable(v): return v ... else: ... raise ValueError('dumbda pr

Re: Bitching about the documentation...

2005-12-05 Thread Bengt Richter
es that would ultimately show up as a single clickable [refs] item at the bottom of pages that have refs, one could tag a post with something like [BeginPythonDocsHarvest] LinkToThisThread: http://docs.python.org/about.html [EndPythonDocsHarvest] I guess I better stop ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Memoizing decorator

2005-12-05 Thread Bengt Richter
. retval = _cache[args] = f(*args, **kw) ... return retval ... class FunMethod(object): ... def __init__(self): self.inst=None ... def __get__(self, inst, cls=None): ... self.inst = inst ... return self ... FunMethod.__call__ = __call__ # to get access to f & _cache ... return FunMethod() ... >>> test_memoize(memoize_FM) fn (eval 1) 1 fn 1 meth (eval 1) 1 meth 1 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Iterating over test data in unit tests

2005-12-05 Thread Bengt Richter
s this do what you want? http://codespeak.net/py/current/doc/test.html#generative-tests-yielding-more-tests Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: i=2; lst=[i**=2 while i<1000]

2005-12-06 Thread Bengt Richter
>>> list(iter(lambda b=[2]:b.append(b[0]**2) or b[0]<1000 and b.pop(0) or >>> None, None)) [2, 4, 16, 256] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: i=2; lst=[i**=2 while i<1000]

2005-12-06 Thread Bengt Richter
ually terminate by >throwing a MemoryError exception when lst and its element values use up >all available space. > >Don't you have an interpreter you could run the code in to verify that >it does indeed loop interminably? You seem to be assuming that the >expression i**2 changes the value of i. It doesn't. > No, but i**=2 does. Are you two talking about the same code? >>> i=2 >>> lst=[] >>> while i<1000: ... i**=2 ... lst.append(i) ... >>> lst [4, 16, 256, 65536] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Calculating Elapsed Time

2005-12-06 Thread Bengt Richter
#x27;Dec 06 2005 14:08:34' >>> time.strftime("%b %d %Y %H:%M:%S", time.gmtime(t2)) 'Dec 06 2005 22:08:34' for more info, see time module docs at http://www.python.org/doc/current/lib/module-time.html and in general, learn how to find info starting at http://www.python.org/doc/ also, interactively, import time help(time) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Binary representation of floating point numbers

2005-12-06 Thread Bengt Richter
File "", line 9, in __getitem__ IndexError: 11L has only 8 bits >>> list(bv11) [1, 1, 0, 1, 0, 0, 0, 0] >>> bv11[::-1] [0, 0, 0, 0, 1, 0, 1, 1] >>> bv11[-1] 0 >>> bv11[-5] 1 >>> bv11[-6] 0 >>> bv11[:4] [1, 1, 0, 1] >>> str(bv11) '1011' >>> repr(bv11) "Bitview(int('1011', 2))" >>> eval(repr(bv11)) == bv11 True >>> import sys >>> Bitview(sys.maxint) Bitview(int('0111', 2)) Add niceties to taste ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: str attributes

2005-12-06 Thread Bengt Richter
discussed, of course ;-) go to http://groups.google.com and put "string module" "str" group:comp.lang.python in the seach slot. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Calculating Elapsed Time

2005-12-07 Thread Bengt Richter
w ;-) BTW time.time is just the 100hz scheduling slice >>> min(filter(None,(-float.__sub__(t(),t()) for x in xrange(1))))**-1 100.9536752259 >>> min(filter(None,(-float.__sub__(t(),t()) for x in xrange(1))))**-1 100.9536752259 >>> min(filter(None,(-f

Re: Calculating Elapsed Time

2005-12-07 Thread Bengt Richter
aven't re-compiled it for current version. Another back burner thing. (I was trying to get CPU chip version detection right so the module would refuse to load if there wasn't a suitable chip, IIRC). Sigh. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Documentation suggestions

2005-12-07 Thread Bengt Richter
IMO the first link above (or for whatever current version) would be nice to find on the documentation sidebar of python's home page (http://www.python.org/), maybe right below the "Beginner's Guide" link. (it's gotten nicer, so maybe I'll snag me a fresh offline-usable copy, and update my Start>Help menu ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: efficient 'tail' implementation

2005-12-09 Thread Bengt Richter
lly signed message part Url : http://mail.python.org/pipermail/python-dev/attachments/20051130/e88db51d/attachment.pgp Might want to throw away the first item returned by frsplit, unless it is !='' (indicating a last line with no \n). Splitting with os.linesep is a problematical default, since e.g. it wouldn't work with the above archive, since it has unix endings, and I didn't download it in a manner that would convert it. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Bengt Richter
syntax just >> to introduce anonymous functions. > >There might not be a return statement: the anonymous function might >conditionally return earlier and have side-effects at the end of the >block (to implicitly return None). So the block-ending would need to >fit after any statement and be strictly unambiguous. Just use parens as necessary or when in doubt ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Lambda as declarative idiom (was RE: what is lambda used for in real code?)

2005-01-04 Thread Bengt Richter
ml >[3]http://mail.python.org/pipermail/python-list/2004-December/257023.html >[4]http://boredomandlaziness.skystorm.net/2004/12/anonymous-functions-in-python.html >[5]http://mail.python.org/pipermail/python-list/2004-December/257893.html >[6]http://mail.python.org/pipermail/python-list/2004-December/257977.html >[7]http://mail.python.org/pipermail/python-list/2005-January/258441.html >[8]http://mail.python.org/pipermail/python-list/2005-January/258238.html Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Is there any way/where to subscribe for automated PEP status emails?

2005-01-05 Thread Bengt Richter
ust bounce replies with some advice as to where to go ;-) Googling didn't hit anything obvious for me. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

type declarations, interfaces, etc as program information composition

2005-01-05 Thread Bengt Richter
nd your interface info says foo(int, int) -> int. Anyway, I consider the Lego-like composability of python programming elements to be one of python's greatest attractions. I hope Guido can figure some way to let us snap in type info without filing existing knobs into new shapes. Regards,

Re: Deferred expressions (was Re: Lambda as declarative idiom)

2005-01-05 Thread Bengt Richter
nd 'from' are already keywords, so there shouldn't be any compatibility >problems. > >Michael Spencer's idea of using 'for' instead of 'from' was quite interesting, >but the use of 'for' without a corresponding 'in' feels a bit misleading :) What was the point of all this again? Pretending lambda goes away without really killing it? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Python evolution: Unease

2005-01-05 Thread Bengt Richter
you are interested in). I don't see why every gee whiz thing has to be on your hard disk from the first. And for those that want a big grabbag, the stubs ought to be designed to to be runnable from a configured script, so you can turn it loose and see what's up IRL. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Python evolution: Unease

2005-01-06 Thread Bengt Richter
On 05 Jan 2005 23:19:39 -0800, Paul Rubin <http://[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] (Bengt Richter) writes: >> What do you think of automated secure importing/installing from a >> remote server? You know, you try to import something and it imports >> a

Re: Building unique comma-delimited list?

2005-01-06 Thread Bengt Richter
># Eliminate the duplicates; probably use set() in Python 2.4 Yup, but 2.3 can be a one-liner too: >>> words = ["foo", "bar", "baz", "foo", "bar", "foo", "baz"] >>> w2 = ('foo' in words and ['foo'] or []) + [w for w in >>> dict(zip(words,words)) if w!='foo'] >>> w2 ['foo', 'baz', 'bar'] Not sorted, but foo is out front. >d = dict() >for w in words: >d[w] = w > >if d.has_key ("foo"): >newWords = ["foo"] >del (d["foo"]) >else: >newWords = [] > >for w in d.keys(): >newWords.append (w) > >s = ', '.join (newWords) >print s > Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Embedding a restricted python interpreter

2005-01-06 Thread Bengt Richter
pile to enable the setuid stuff. But IIRC after that you can run cgi with everything private and serve only generated stuff to the world if you want. >- use different webservers per user, put them together with mod_proxy (yuck= >!) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Other notes

2005-01-06 Thread Bengt Richter
(1, 8), (1, 10), 'a=b+c; a+=2; x..y') (2, '2', (1, 10), (1, 11), 'a=b+c; a+=2; x..y') (51, ';', (1, 11), (1, 12), 'a=b+c; a+=2; x..y') (1, 'x', (1, 13), (1, 14), 'a=b+c; a+=2; x..y') (51, '.', (1, 14), (1, 15), 'a=b+c; a+=2; x..y') (51, '.', (1, 15), (1, 16), 'a=b+c; a+=2; x..y') (1, 'y', (1, 16), (1, 17), 'a=b+c; a+=2; x..y') (0, '', (2, 0), (2, 0), '') Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Other notes

2005-01-07 Thread Bengt Richter
On Fri, 07 Jan 2005 06:04:01 GMT, Andrew Dalke <[EMAIL PROTECTED]> wrote: >Bengt Richter: >> But it does look ahead to recognize += (i.e., it doesn't generate two >> successive also-legal tokens of '+' and '=') >> so it seems it should be a si

Re: args (was Re: Lambda as declarative idiom (was RE: what is lambda used for in real code?))

2005-01-07 Thread Bengt Richter
> > args["arg1"] > > (i.e., only args defined in argspec are accepted) > > * Useful infrastructure for user-supplied type-based dispatch/lightweight >multimethods: > > argspec = args([(a:int, b:int),(a:str,b

Re: Securing a future for anonymous functions in Python

2005-01-07 Thread Bengt Richter
def foo(f=bar): print f() ... >>> def bar(): return 'this is updated bar' ... >>> foo() this is bar >>> def foo(f=lambda:bar()): print f() ... >>> foo() this is updated bar >>> def bar(): return 'this updated bar was picked up by silly lambd

Re: Python Operating System???

2005-01-07 Thread Bengt Richter
e for writing OS's. > >(I know that you mentioned C++, not C, but I decided to setup C as a >straw-man to make my argument.) I'd say look at Ada for HLL inspiration, if you want to deal with OS level stuff in Python. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Notification of PEP Updates

2005-01-07 Thread Bengt Richter
gt;The URL for the mailing list is: >http://mail.python.org/mailman/listinfo/python-checkins > >I believe the mail you receive should contain the checkin messages, along with >a >summary of the differences between the old version and the new version (handy >if >you

Re: OT: google groups bug, or worse?

2005-01-07 Thread Bengt Richter
ML+framework+provides+a+flexible+and+well+defined+infrastructure%22&qt_s=Search+Groups I.e., searching for one of the first lines in your references "The xsdbXML framework provides a flexible and well defined infrastructure" in google groups. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Securing a future for anonymous functions in Python

2005-01-07 Thread Bengt Richter
not that big a deal. > >I also just can't believe that Pythonistas keep getting into these >arguments over whether lambda is too confusing, while at the same time >there's no such discussion over far more abstruse Python features like >metaclasses. Some things are considered to be behind the pythonostasis and only for the priests? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Notification of PEP Updates

2005-01-07 Thread Bengt Richter
On Fri, 07 Jan 2005 16:05:31 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> On Sat, 08 Jan 2005 03:28:34 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote: >> >> >>>I can't recall which thread this came up in, so I'm st

Re: Other notes

2005-01-08 Thread Bengt Richter
On Sat, 08 Jan 2005 18:22:53 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> IOW, I think there is a fix: keep tokenizing greedily and tokenize floating >> point as >> a sequence of integers and operators, and let be >> translated by

Re: python3: 'where' keyword

2005-01-08 Thread Bengt Richter
x = ( foo(x) where: x = math.pi/4.0 ) where: def foo(x): print 'just for illustration', x or is this legal? for y in ([foo(x) for x in bar] where: bar = xrange(5) ): baz(y) where: def baz(arg): return arg*2

Re: Python Operating System???

2005-01-08 Thread Bengt Richter
of "canned" byte sequences built by hand and stuck >into the appropriate places in memory... Well, usually there's more than one tool in the chain from source to bootable loader and OS image, even if you are writing in C and assembler, and there's usually more to an OS than

Re: python3: 'where' keyword

2005-01-08 Thread Bengt Richter
On 8 Jan 2005 16:13:39 -0800, "Carl Banks" <[EMAIL PROTECTED]> wrote: > >Bengt Richter wrote: >> And, is the whole thing after the '=' an expression? E.g., >> >> x = ( foo(x) where: >> x = math.pi/4.0 >> ) where: &

Re: Python Operating System???

2005-01-08 Thread Bengt Richter
On Sat, 8 Jan 2005 21:29:47 -0600, "John Roth" <[EMAIL PROTECTED]> wrote: > >"Bengt Richter" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> On Sat, 08 Jan 2005 12:47:52 -0500, Peter Hansen <[EMAIL PROTECTED]> >> wrot

Re: python3: 'where' keyword

2005-01-09 Thread Bengt Richter
look at it, so it doesn't matter whether it's >easily readable. There's no reason to add needless constraints on the >language just to make writing ugly code difficult. The main goal >should be to make writing clear code easy, not to worry about whether >someone might also wr

Re: python3: accessing the result of 'if'

2005-01-09 Thread Bengt Richter
tements, too. > >if someregexp.match(s) as m: > # blah using m >elif someotherregexp.match(s) as m: > # blah using m > If 'where: ...' were an expression suite ISTM you could write if m where: m = someregexp.match(s) # same-line format blah(m) eli

Re: time module precision

2005-01-09 Thread Bengt Richter
al-time stuff, but I haven't used it. (I just seem to remember reading something about that in the MSDN docs, but I am not sure. And too lazy to go back and look ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Dr. Dobb's Python-URL! - weekly Python news and links (Jan 9)

2005-01-10 Thread Bengt Richter
>eliminating the need to move the lips (which reduces effort and stops >flies getting in). > >Tim C >Sydney, Australia LOL. Thanks, needed that ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Python serial data aquisition

2005-01-11 Thread Bengt Richter
hand with redundant information that will accomplish the effect of masking and shifting and adjusting sign. If you need this speed, volunteers will magically appear. Maybe even if you don't ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing huge Sets() to disk

2005-01-11 Thread Bengt Richter
>[cut] > > The reason I went for sets instead of lists is the speed, >availability of unique, common and other methods. >What would you propose as an elegant solution? >Actually, even those nested for loops take ages. :( If you will explain a little what you are doing with these set "items" perhaps someone will think of another way to represent and use your data. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Securing a future for anonymous functions in Python

2005-01-11 Thread Bengt Richter
urn preset # return now legal ... print foo() The combination would work like: let(rebindable): factor = 10 in bar: rebindable *= factor rebindable = 2 bar() print rebindable # => 20 rebindable += 5 bar() print rebindable # => 250 You can see this could be used nicely in case functionality, with a dict of named in-functions. What do you think? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Python serial data aquisition

2005-01-11 Thread Bengt Richter
On 11 Jan 2005 07:51:35 -0800, [EMAIL PROTECTED] (Flavio codeco coelho) wrote: >[EMAIL PROTECTED] (Bengt Richter) wrote in message news:<[EMAIL PROTECTED]>... >> On 9 Jan 2005 14:13:28 -0800, [EMAIL PROTECTED] (Flavio codeco coelho) wrote: >> >> >Hi, >> >

Re: Another look at language comparisons

2005-01-12 Thread Bengt Richter
/www.tbray.org/ongoing/When/200x/2004/12/08/-big/IMG_3061.jpg >> >> >> LOL, he is working on linux, isn't he? >> >> So it was about bloody time. > >Guido Van Rossum is now working on linux?? Are they both left-handed? Hm, sinister ... Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Refactoring; arbitrary expression in lists

2005-01-12 Thread Bengt Richter
deas? > I think I would refactor along these lines: (untested) extensiondict = dict( php = 'application/x-php', cpp = 'text/x-c-src', # etcetera xsl = 'test/xsl' ) def detectMimeType(filename): extension = os.path.splitext(filename)[1].replace('.', '') try: return extensiondict[extension] except KeyError: basename = os.path.basename(filename) if "Makefile" in basename: return 'text/x-makefile' # XXX case sensitivity? raise NoMimeError Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: counting items

2005-01-12 Thread Bengt Richter
(map(totallen, x)) > return 1 Since the requirement is to _count_, not flatten, ISTM your solution is best so far ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: dict.updated

2005-01-12 Thread Bengt Richter
#x27;: 10, 'c': 3}] > It's kind of a strange list comp, but I guess you're just illustrating something. But for this case you could just write >>> [d.update({'c':3}) or d for d in [{'a':1, 'b':2}, {'x':10, 'y':'11'}]] [{'a': 1, 'c': 3, 'b': 2}, {'y': '11', 'x': 10, 'c': 3}] taking advantage of normal d.update() returning None and so forcing the 'or' term. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: pyserial and com port interrupts

2005-01-12 Thread Bengt Richter
u set baud rates and handshaking etc. I would think. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: What strategy for random accession of records in massive FASTA file?

2005-01-12 Thread Bengt Richter
ATTCTCAAAGGAATAGACGG >>CW127_A03 >TGCAGTCGAACGAGAACGGTCCTTCGGGATGTCAGCTAAGTGGCGGACGGGTGAGTAATG >TATAGTTAATCTGCCCTTTAGAGATAACAGTTGGAAACGACTGCTAATAATA >GCATTAAACATTCCGCCTGGG >... Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Refactoring; arbitrary expression in lists

2005-01-12 Thread Bengt Richter
On Thu, 13 Jan 2005 12:19:06 +1000, Stephen Thorne <[EMAIL PROTECTED]> wrote: >On Thu, 13 Jan 2005 01:24:29 GMT, Bengt Richter <[EMAIL PROTECTED]> wrote: >> extensiondict = dict( >> php = 'application/x-php', >> cpp = 'tex

Re: why are people still using classic classes?

2005-01-12 Thread Bengt Richter
gt;> def MC(*a): print a; return type(*a) ... >>> class F: ... __metaclass__ = MC ... pass ... ('F', (), {'__module__': '__main__', '__metaclass__': }) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: finding/replacing a long binary pattern in a .bin file

2005-01-13 Thread Bengt Richter
fout = open('mynewbinfile', 'wb') for buf in updated_file_stream('myoldbinfile','rb', oldbinstring, newbinstring): fout.write(buf) fout.close() (left as an exercise ;-) (modifying a file "in place" is another exercise) (doing the latter with defined maximum memory buffer usage even when mods increase the length of the file is another ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-13 Thread Bengt Richter
... inner() ... print 4, locals() ... >>> foo() 1 {'a': 1, 'b': 2} 2 {'a': 2, 'c': 3, 'b': 2} and b: 2 4 {'a': 1, 'b': 2, 'inner': } of course a difference using the new syntax is that 'inner' is not bound to a persistent name. > >otherwise that would be impossible to do calculations based on scope >variables and "using:" would be useless =), consider example of usage: > >current_position = 1 >current_environment # = ... >current_a_lot_of_other_parameters # = ... >scores = [count_score(move) for move in aviable_moves] using: > def count_score(move): > #walking through current_environment > return score No worry, UIAM. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-13 Thread Bengt Richter
27;s let(x, y, ...): spec. It provides a new way of factoring. As well as things no one has thought of yet ;-) The other thing to think about is that the let suite could be strictly def-time, which would provide the opportunity to avoid re-calculating things in functions without abusing default args, and using the easy closure-variable creation instead. E.g., let(foo): preset = big_calc() in: def foo(x): return x * preset (This "in:" has no "in xxx:" name, so the effect is immediate execution of the anonymously defined function, which writes through to foo with the def, as permitted by let(foo):). Problems? (Besides NIH, which I struggle with regularly, and had to overcome to accept Tim's starting point in this ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: python and macros (again) [Was: python3: 'where' keyword]

2005-01-13 Thread Bengt Richter
has justified the fact that an >assignment does not return any value, and therefore cannot be used as a >component of an expression. > Hm, that makes me wonder, is there an intermediate "returning of value" in x = y = z = 123 ? >Mea culpa, but I'm not going to *pl

Re: Octal notation: severe deprecation

2005-01-13 Thread Bengt Richter
g hex literals of negative numbers. def __repr__(self): return '<%s object at %08.16b>' %(type(self).__name__, id(self)) and you could write based literals in the above formats with e.g., with '16x%.16b' % number or '2x%.2b' % number etc. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie q

2005-01-13 Thread Bengt Richter
15], [16], [17], [18], [19]] >>> for i in (x[0] for x in something): print i, ... oops, that list() used it up ;-) >>> something = [[x] for x in xrange(10,20)] >>> for i in (x[0] for x in something): print i, ... 10 11 12 13 14 15 16 17 18 19 Really nice. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: finding/replacing a long binary pattern in a .bin file

2005-01-13 Thread Bengt Richter
On Thu, 13 Jan 2005 11:40:52 -0800, Jeff Shannon <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> BTW, I'm sure you could write a generator that would take a file name >> and oldbinstring and newbinstring as arguments, and read and yield nice >> os-file-s

Re: Octal notation: severe deprecation

2005-01-13 Thread Bengt Richter
On Thu, 13 Jan 2005 17:43:01 -0600, Jeff Epler <[EMAIL PROTECTED]> wrote: > >--LQksG6bCIzRHxTLp >Content-Type: text/plain; charset=us-ascii >Content-Disposition: inline >Content-Transfer-Encoding: quoted-printable > >On Thu, Jan 13, 2005 at 11:04:21PM +, Bengt Rich

Re: finding/replacing a long binary pattern in a .bin file

2005-01-14 Thread Bengt Richter
On Thu, 13 Jan 2005 11:40:52 -0800, Jeff Shannon <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> BTW, I'm sure you could write a generator that would take a file name >> and oldbinstring and newbinstring as arguments, and read and yield nice >> os-file-s

Re: Class initialization from a dictionary, how best?

2005-01-14 Thread Bengt Richter
g to list the variable names ># as strings in multiple places. It is enought to ># have them in the 'mapping' ># dictionary above > >t2 = Test(dictionary.get('a'), dictionary.get('b'), >dictionary.get('c')) >print t2 > Why don't

Re: Octal notation: severe deprecation

2005-01-14 Thread Bengt Richter
On Fri, 14 Jan 2005 20:13:48 +0100, Reinhold Birkenfeld <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> On Thu, 13 Jan 2005 08:18:25 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote: >> >>>[EMAIL PROTECTED] wrote: >>>> In Mythical Future P

Re: Class initialization from a dictionary, how best?

2005-01-14 Thread Bengt Richter
#x27;s as needed in a pool of partially complete t's. But your real requirements are not clear enough here, so you may get help crossing a stream, but no one will be able to say you are already on the side of the stream you want to be later, and there's an easy path without need of crossing twice ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: finding/replacing a long binary pattern in a .bin file

2005-01-14 Thread Bengt Richter
import sys try: oldnew = __import__(sys.argv[3]) main(sys.argv[1], sys.argv[2], oldnew.old, oldnew.new) except Exception, e: print '%s:%s' %(e.__class__.__name__, e) raise SystemExit, """ Usage: [python] binfupd.py infname outfname oldnewmodulename where infname is read in binary, and outfname is written in binary, replacing instances of old binary data with new specified as python strings named old and new respectively in a module named oldnewmodulename (without .py extension). """ --- REMEMBER: NO WARRANTY FOR ANY PURPOSE! USE AT YOUR OWN RISK! And, if you know where to seek to, that seems like the best way ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: java 5 could like python?

2005-01-15 Thread Bengt Richter
interpreter, just type "quit". To get a list of available modules, keywords, or topics, type "modules", "keywords", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose summaries contain a given word such as "spam", type "modules spam". Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: What strategy for random accession of records in massive FASTA file?

2005-01-15 Thread Bengt Richter
nerally speaking you can ignore the overhead, and the >flush() calls will be automatic as long as you don't mix file and string >operations. The programming convenience is amazing. That part does look good, but will scanning a large file with find cause massive swapouts, or is there some smart prioritization or hidden sequential windowing that limits mmap's impact? > >> -- >> I have come to kick ass, chew bubble gum and do the following: >> >> from __future__ import py3k >> >> And it doesn't work. > >So make it work :-) > Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to del item of a list in loop?

2005-01-16 Thread Bengt Richter
ut once again ;-) >>> lst = [1, 2, 3] >>> i = 0 >>> for item in lst: ...if item !=2: ...lst[i] = item ...i += 1 ... >>> del lst[i:] >>> lst [1, 3] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

<    1   2   3   4   5   6   7   8   9   10   >