Re: Proposal: Inline Import

2005-12-11 Thread Bengt Richter
On Sat, 10 Dec 2005 19:40:08 -0800, Robert Kern <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> Are you willing to type a one-letter prefix to your .re ? E.g., >> >> >>> class I(object): >> ... def __getattr__(self, attr): >> ...

Re: Random Number Generation?

2005-12-11 Thread Bengt Richter
urnmix(1, 5, 90, 5)].count(True) 497 >>> [u==int(u) for u in urnmix(10000, 5, 90, 1)].count(True) 111 >>> [u==int(u) for u in urnmix(1, 5, 90, 1)].count(True) 87 >>> [u==int(u) for u in urnmix(1, 5, 90, 1)].count(True) 113 After all this playing, what was it you actually wanted? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: OO in Python? ^^

2005-12-11 Thread Bengt Richter
berties with your sig ;-) ,<@>< °º¤øø¤º°`°º¤øø¤º°P`°º¤ø,,y,,ø¤º°t`°º¤ø,,h,,ø¤º°o`°º¤ø,,n,,ø¤º° Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: slice notation as values?

2005-12-12 Thread Bengt Richter
enoomerate = enoomerate() >>> >>> import string >>> lst = list(string.ascii_lowercase) # legit list, though could use the >>> string >>> for el in enoomerate[lst, ::2]: print el, ... (0, 'a') (2, 'c') (4, 'e') (6, 'g') (8, 'i') (10, 'k') (12, 'm') (14, 'o') (16, 'q') (18, 's') ( 20, 'u') (22, 'w') (24, 'y') >>> for el in enoomerate[lst, 3::3]: print el, ... (3, 'd') (6, 'g') (9, 'j') (12, 'm') (15, 'p') (18, 's') (21, 'v') (24, 'y') >>> for el in enoomerate[lst, 3]: print el, ... (0, 'a') (1, 'b') (2, 'c') >>> for el in enoomerate[lst, 3:6]: print el, ... (3, 'd') (4, 'e') (5, 'f') >>> for el in enoomerate[lst, 3:6:2]: print el, ... (3, 'd') (5, 'f') Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: lambda (and reduce) are valuable

2005-12-12 Thread Bengt Richter
t;, 2, 2); digit("6", 3, 2) >digit("1", 1, 3); digit("2", 2, 3); digit("3", 3, 3) > >are people still missing that local functions are inexpensive in Python ? OTOH, (untested) for label, x, y in ((str(d+1), d%3+1, 3-d//3) for d in xrange(9)): Button(label=label, command=lambda d=int(label):user_pressed(d)).grid(column=x, row=y) or for tup in ((str(d+1), d%3+1,3-d//3) for d in xrange(9)): digit(*tup) tweak 'til correct ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with Lexical Scope

2005-12-12 Thread Bengt Richter
per(8, 3) bump3() => 11 bump3() => 14 I wonder if a function would fly better than a punctuation tweak on bare name assignment ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with Lexical Scope

2005-12-12 Thread Bengt Richter
On 12 Dec 2005 01:23:48 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >Thanks for the example code. Definately provided a few different ways >of doing the construction. > >Actually, the status variable was the only thing that mattered for the >inner function. The first code post had a bug

Re: newbie: generate a function based on an expression

2005-12-13 Thread Bengt Richter
12 LOAD_GLOBAL 4 (A) 15 LOAD_FAST0 (x) 18 BINARY_MULTIPLY 19 LOAD_GLOBAL 6 (off) 22 BINARY_ADD 23 CALL_FUNCTION2 26 CALL_FUNCTION2

Re: Still Loving Python

2005-12-14 Thread Bengt Richter
u like, even using x86 builtin assembler. And it compiles and links _hella_ faster than C/C++ ;-) And you can make DLLs, and link also with non-Delphi. Not that I've used it for quite some time, though ;-) Anyway, I wouldn't diss Delphi too casually. I don't think you would if you'd spent enough time to get fluent in it. (I don't know what the current state of Delphi is though. I'm speaking from experience mostly with the ancient Delphi3 whose output you see above ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Still Loving Python

2005-12-14 Thread Bengt Richter
On Wed, 14 Dec 2005 10:07:04 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] (Bengt Richter) writes: >> A single click compiles, links and runs the resulting independent windows >> .exe in a fraction of a second >> for the above, and I can see the hin

Re: ?: in Python

2005-12-14 Thread Bengt Richter
gt;In [3]:print a >2 > You won't like it in a case like a = (2**20**20, 2)[switch] or a = (m/n, sys.maxint)[n==0] the point is that if/else only evaluates the expression in one branch, as with C ternary. You're right, there is a PEP and a ternary expression coming to python though. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: to write set of values to a file from python

2005-12-14 Thread Bengt Richter
nt. >>> csv_writer.writerow(['empties:', None, '',[], (), {}, False]) empties:,,,[],(),{},False Looks like None and '' translate to the same empty fields (nothing between delimiting commas) but the other stuff is getting converted by str or repr (we'll c

Re: access to preallocated block of memory?

2005-12-15 Thread Bengt Richter
? You could define a pure python vxresrvedmem module that just simulates the real thing, to test ideas -- and to communicate more clearly to us what the problem is. What modules/libraries do you have to give you access now from python to the vxworks environment? A file system? /dev/magic_stuff

Re: Overlapping Regular Expression Matches With findall()

2005-12-15 Thread Bengt Richter
... expensive for a list containing thousands of matches. ... """ >>> import re >>> rxo = re.compile(r'cat(?:er|e)?') >>> rxo.findall(s) ['cate', 'cat', 'cate', 'cater', 'cate'] >>> seen

Re: Problem with Lexical Scope

2005-12-16 Thread Bengt Richter
ule(record): if not ((("length" in record) and ("width" in record))): return NotImplemented return (eq_test(record['length'], record['width'])) def rule(record): if not ((("length" in record) and ("width" in record))): return NotImplemented return ((record['length'] == record['width'])) So the "collectable" eq for box_rule (second debug output) generated in-line code, which will run faster. >>> jslowery.rule({'length':2, 'width':2}) True >>> jslowery.rule({'length':2, 'width':1}) False >>> jslowery.rule({'height':2, 'width':1}) NotImplemented >>> jslowery.box_rule({'height':2, 'width':1}) NotImplemented >>> jslowery.box_rule({'length':2, 'width':1}) False >>> jslowery.box_rule({'length':2, 'width':2}) True Looks like I didn't need all the parens ;-) Anyway, this is not well tested, but rules constructed this way should run a lot faster than doing all the nested calling at run time. There are always security issues in exec-ing or eval-ing, so I am not recommending the above as secure from malicious rule-writers, obviously. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with Lexical Scope

2005-12-16 Thread Bengt Richter
se declared, and just e.g. "name!" would be short for "have(name)", then just use some format like (assuming 'rules' is a name for a particular group of rules) functions:: "is_ssn" # predeclare user-defined function names operators:: "and", "<" # might be implicit rules: first_name!; last_name!; ssn! and is_ssn(ssn); birth_date! and hire_date! and (birth_date < hire_date) or with identation, and messages after a separating comma a la assert rules: first_name!, 'Missing first name' # or ('MISSING_VALUE', 'FIRST_NAME') tuple as args for your locale thing last_name!, 'Missing last name' ssn! and is_ssn(ssn), 'Invlaid ssn' # => 'ssn' in record and is_ssn(record['ssn'] birth_date! and hire_date! and (birth_date < hire_date) # => 'birtdate' in record and 'hire_date' in record and # record['birth_date'] < record['hire_date'] more_rules: field_name!, 'field name is missing' etc ... Seem like it would be fairly easy to translate to code in a function per rule group, without any fancy parsing. I don't like XML that much, but that might be a possible representation too. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Next floating point number

2005-12-17 Thread Bengt Richter
On Sat, 17 Dec 2005 14:23:38 +1100, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >I'm looking for some way to get the next floating point number after any >particular float. > >(Any mathematicians out there: I am aware that there is no "next real >number". But floats are not real numbers, they only

Re: Problem with Lexical Scope

2005-12-17 Thread Bengt Richter
ay of rewriting the AST, which would potentially allow folding constant expressions that may be formed when parameters become constants, etc. So I haven't pursued byte code munging much further. The version above only had minor testing, and only on python 2.4. IOW, basically a proof of concept. I based my presets/curry decorator on the pattern of a decorator Raymond Hettinger wrote, which optimizes global accesses and other stuff. No warranties, mind! ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Next floating point number

2005-12-18 Thread Bengt Richter
On Sun, 18 Dec 2005 10:27:16 +1100, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Sat, 17 Dec 2005 09:26:39 +, Bengt Richter wrote: > > >> I wonder if this won't work (for IEEE 754 double that is) ^^^[1] >&

Re: Accessing next/prev element while for looping

2005-12-18 Thread Bengt Richter
'a' 'b' 'a' 'b' 'c' 'b' 'c' 'd' 'c' 'd' 'e' 'd' 'e' 'f' 'e' 'f' '\x0

Re: how to remove duplicated elements in a list?

2005-12-19 Thread Bengt Richter
,1,2,3,'x',1,2,1,2,1,3])) [1, 2, 3, 'x'] >>> list(set([1,'y',2,3,1,2,3,'x',1,2,1,2,1,3])) ['y', 1, 2, 3, 'x'] I'd say it does have the chance of changing the order ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Can you pass functions as arguments?

2005-12-19 Thread Bengt Richter
38350 which seems to agree with >>> def sum100(f): ... s = 0 ... for i in xrange(101): ...s += f(i) ... return s ... >>> sum100(square) 338350 or if the OP actually wants the specific function, >>> def sum100a(f): return sum(imap(f, xrange(101))) ... >>> sum100a(square) 338350 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Enumeration idioms: Values from different enumerations

2005-12-20 Thread Bengt Richter
ed as a (handy because predefined) logically true sentinel value to return from a test function to distinguish not_applicable from applicable_and_ok when desired, yet allowing assert testfun(...) to succeed either way. That code would have to use another boolishly True sentinel if NotImplemented

Re: Parsing text

2005-12-20 Thread Bengt Richter
r, depending on your matching criteria (e.g., case-sensitive fixed string vs regular expression). Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Do you recommend a good artificial intelligence book?

2005-12-20 Thread Bengt Richter
well as Lisp code. The intent is to implement all the algorithms in both languages, so that you can choose whichever language you prefer. As yet neither implementation is complete, but the Lisp version is closer. """ BTW, Peter Norvig is co-author ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: parsing engineering symbols

2005-12-20 Thread Bengt Richter
t some function which would return 12000 > function(s) > => 12000.0 > I searched the web, but could not find any function. > It should be easy enough, if you can define precisely what "contains engineering symbols" means ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: pythonic equivalent of upvar?

2005-12-20 Thread Bengt Richter
e ValueError, "%r may not be overridden" % name ValueError: 'securityLevel' may not be overridden Quoting command line arg to make a single arg with embedded spaces: [ 9:54] C:\pywk\ut>py24 clvalues.py -added "should be string" decode: 0 securityLevel: 3

Re: Parsing text

2005-12-20 Thread Bengt Richter
ation: New York [15:20] C:\pywk\clp>md xd [15:20] C:\pywk\clp>py24 extractfilesegs.py -tf xd (Jimmy) Files created: "xd\jimmy.txt" < xd\jimmy.txt > Jimmy Current Location: Denver Next Location: Chicago [15:21] C:\pywk\clp>py24 extractfilesegs.py -tf xd "Person: (Sarah)" Files created: "xd\sarah.txt" < xd\sarah.txt > Person: Sarah Current Location: San Diego Next Location: Miami Next Location: New York [15:22] C:\pywk\clp>py24 extractfilesegs.py -tf xd "^(irrelevant)" Files created: "xd\irrelevant.txt" < xd\irrelevant.txt > irrelevant trailing stuff ... HTH, NO WARRANTIES ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: parsing engineering symbols

2005-12-21 Thread Bengt Richter
x27;:-24 >} > >def myfloat(str): >try: >exp = SI_prefixes[str[-1]] >return float(str[:-1]) * 10**exp >except KeyError: >return float(str) > >? Nit: why not move 10** out of myfloat into SI_prefixes (i.e., just retrieve precalculated factors)? Nit_2: No twinge of conscience shadowing str? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Easiest way to calculate number of character in string

2005-12-21 Thread Bengt Richter
-1: '' 0: '' 1: ';' 2: ';;' 3: '' I.e., Zeile += ';'*(42-Zeile.count(';')) should work, since a string is a sequence type and http://docs.python.org/lib/typesseq.html Says """ Operation ResultNotes ... s * n , n * s n shallow copies of s concatenated(2) ... (2) Values of n less than 0 are treated as 0 (which yields an empty sequence of the same type as s). ... """ I guess it might be nice to mention this in help(str) also, to publish a useful fact better. Maybe under str.__mul__ ? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Reducing import try/except boilerplate

2005-12-21 Thread Bengt Richter
e') h = '' import g or (h or g) or h as mod # (h or g) is a string expression => 'gname' here Also, a bare 'and' could make its predecessor term be treated like an ordinary expression (even if a bare name), allowing bare guard condition expressions, e.g., import cond and name or alternate as mod # <==> import (cond and 'name') or alternate as mod Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Guido at Google

2005-12-21 Thread Bengt Richter
Appears to be the google number But the official conversion >>> 1000/39.37 25.400050800101603 is not _exactly_ 25.4 mm/inch so the distance from Martellibot to BDFL should more exactly be >>> 15*39.37/12 49.2124999 Send bug report to google ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Guido at Google

2005-12-22 Thread Bengt Richter
On Wed, 21 Dec 2005 21:47:29 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >[roughly "an inch is not exactly 25.4mm"] >> At least according to my dusty 37th Edition Handbook of Chemistry and >> Physics (c) 1955. >> Maybe things

Re: Guido at Google

2005-12-22 Thread Bengt Richter
On Wed, 21 Dec 2005 18:30:03 -0700 (MST), Jim Benson <[EMAIL PROTECTED]> wrote: >On Thu, 22 Dec 2005, Bengt Richter wrote: > >> >> >> >> For Americans: 15 meters is roughly 50 feet. >> > >> >Google can do that too, of course. >> &g

Re: deal or no deal

2005-12-22 Thread Bengt Richter
gt;> len(amounts) 26 is the total number of numbers So if you choose with uniform probability, you'd expect >>> 19./26 0.73076923076923073 to be the fraction satisfying pick<10 With a larger sample, the fraction should show better, e.g., >>> sum(random.choice(amounts)<10 for _ in xrange(100)) 730983 Does that help? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Guido at Google

2005-12-22 Thread Bengt Richter
did;-). > So is google about to determine how many luminaries can fit on the head of a project? ;-) Seriously, if you heavies do sometimes work on the same project, it would be interesting to know what modes of co-operation you tend to adopt. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Providing 'default' value with raw_input()?

2005-12-22 Thread Bengt Richter
.items(): print '%10s: %.2f'%(name,price) ... yoghurt: 1.19 banana: 0.79 apple: 1.23 I'm not suggesting this as a pattern to follow, just to illustrate what you can do with raw_input. IOW, it's about how you build the prompt string, and what you do with the user response input string that solves your problem. Voluminous prompts get old fast, so you might e.g. want to accept a '?' to get extra context-sensitive info instead, followed by retry. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: jython: True and False boolean literals?

2005-12-22 Thread Bengt Richter
e "(1==1)" and "(1==0)". > You may want to upgrade to a newer version. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Providing 'default' value with raw_input()?

2005-12-22 Thread Bengt Richter
On 22 Dec 2005 12:42:36 -0800, "planetthoughtful" <[EMAIL PROTECTED]> wrote: > >Bengt Richter wrote: >> On 22 Dec 2005 08:55:17 -0800, "planetthoughtful" <[EMAIL PROTECTED]> wrote: >> > >> >I would like to include the ability to edit

Re: Guido at Google

2005-12-23 Thread Bengt Richter
> It's like having James Bond as your very own personal body guard ;) > >That is such a nice quote that I am going to put it in my email >signature ! :) > >-Anand > Maybe look into fixing the above problem while you're at it? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Logging: Formatter: name of the function

2005-12-23 Thread Bengt Richter
f not __debug__: return f ... def wrap(*args, **kw): ... print 'before entering function "%s" ...'%f.func_name ... result = f(*args, **kw) ... print 'after returning from function "%s" ...'%f.func_name ... return result ... wrap.func_name = f.func_name # make it look the same if desired ... return wrap ... >>> @debugdeco ... def foo(something): print something; return 'whatever' ... >>> foo('hello') hello 'whatever' You could still do stuff unconditionally of course, and also inside foo. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: python coding contest

2005-12-26 Thread Bengt Richter
On Sun, 25 Dec 2005 16:39:47 +0100, Simon Hengel <[EMAIL PROTECTED]> wrote: >Hello, >we are hosting a python coding contest an we even managed to provide a >price for the winner... ^ > How much are you going to sell him or her for? ;-) Regards, Bengt Richter -- http

Re: Windows and python execution

2005-12-26 Thread Bengt Richter
How did you go from the PATHEXT "clue" to the set command you specify and decide not to set pathext, e.g., by something like set PATHEXT=%PATHEXT%;.py Does your set do the pathext and assoc and ftype all in one swell foop? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: python coding contest

2005-12-28 Thread Bengt Richter
28] C:\pywk\clp\seven\pycontest_01>wc -lc seven_seg.py 2136 seven_seg.py 2 lines, 136 chars including unix-style lineseps (is that cheating on windows?) No imports. Guess I'll have to try another tack ;-/ Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Hypergeometric distribution

2006-01-02 Thread Bengt Richter
ong_Factorial_Integer) ISTM you wouldn't get zero if you scaled by 10**significant_digits (however many you require) before dividing. E.g., expected hits per trillion (or septillion or whatever) expresses probability too. Perhaps that could work in your calculation? Regards, Bengt Richter -

Re: Translate this to python?

2006-01-04 Thread Bengt Richter
On 3 Jan 2006 17:42:44 -0800, "KraftDiner" <[EMAIL PROTECTED]> wrote: >I'm porting a routing from C++ to python. >There is a complex for loop that I don't know how to code in python > >for (i = nPoints-1, j = 0; j < nPoints; i = j, j++) > Perhaps most directly comparable semantics (untested): i =

Re: Hypergeometric distribution

2006-01-04 Thread Bengt Richter
culate >the hypergeometric hence the factorial for numbers within a large range >e.g. choose(14000,170) or choose(5,2) > It seems you are hinting at some accuracy requirements that you haven't yet explained. I'm curious how you use the values, and how that affects your judgement of S

Re: itertools.izip brokeness

2006-01-04 Thread Bengt Richter
ing until but not including (sentinel,)*len(seqs) This would seem backwards compatible, and also potentially allow you to use the rest mode from the start, as in for tup in izip(*seqs).rest(sentinel): # process tup and notice sentinel for yourself Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: inline function call

2006-01-05 Thread Bengt Richter
ined inline functions in mymod.py to have been inlined in the code of mymod. I've been meaning to do a proof of concept, but I've hinted at these things before, and no one seems much interested. And besides it's really a distraction from more radical stuff I'd like to try ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-05 Thread Bengt Richter
pable of alternative, non-C implementation of the python semantics. So I thought I'd try this as a possible terminology, to see if it makes it any easier for anyone ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Hypergeometric distribution

2006-01-05 Thread Bengt Richter
On Thu, 05 Jan 2006 09:47:02 -0600, Robert Kern <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> On 4 Jan 2006 12:46:47 -0800, "Raven" <[EMAIL PROTECTED]> wrote: > >>>The problem with Stirling's approximation is that I need to calculate >&

Re: itertools.izip brokeness

2006-01-05 Thread Bengt Richter
and izip will never stop. But you can fix that (only test is what you see ;-) : >>> from itertools import repeat, chain, izip >>> it = iter(lambda z=izip(chain([3,5,8],repeat("Bye")), >>> chain([11,22],repeat("Bye"))):z.next(), ("Bye","Bye")) >>> for t in it: print t ... (3, 11) (5, 22) (8, 'Bye') (Feel free to generalize ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: itertools.izip brokeness

2006-01-05 Thread Bengt Richter
On Thu, 05 Jan 2006 07:42:25 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote: >On 4 Jan 2006 15:20:43 -0800, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote: > [ ... 5 options enumerated ... ] >> >> >6. Could modify izip so that one could write > >from it

Re: itertools.izip brokeness

2006-01-06 Thread Bengt Richter
On 5 Jan 2006 14:34:39 -0800, [EMAIL PROTECTED] wrote: > >Bengt Richter wrote: >> On 5 Jan 2006 15:48:26 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote: >> >> >On 2006-01-04, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> >><[EMAIL

Re: Does Python allow access to some of the implementation details?

2006-01-07 Thread Bengt Richter
'.__mod__, bitsof(3**100, 8))[::-1]) '005A4653CA673768565B41F775D6947D55CF3813D1' >>> ''.join(map('%02X'.__mod__, bitsof(-3**100, 8))[::-1]) 'FFA5B9AC3598C897A9A4BE088A296B82AA30C7EC2F' >>> hex(-3**100) '-0x5A4653CA673768565B41F775D6947D55CF3813D1L' (I leave it to your judgement as to how useful our current hex() representation of negative numebers is ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Viewing Binary Data

2006-01-08 Thread Bengt Richter
xcept binary? Want to give a clue as to output format? Gapped? Ascii at the right? Bit numbers or hex byte offsets at the left? Do you need a one-liner solution? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: question about mutex.py

2006-01-08 Thread Bengt Richter
ciation with the distribution of digital generic products to make them distinguishable for any business purpose whatever. IP principles established with corn flakes and decoder rings are thought to translate perfectly to the digital domain of FOSS distros including anything toy-like. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiway Branching

2006-01-08 Thread Bengt Richter
x27; %((byte1,byte2), pairvalues.get((byte1,byte2), 'DEFAULT ??')) ... (66, 32) => 0.16701 (32, 1) => 5 (36, 32) => 'natural' (32, 32) => 0 (20, 20) => 'DEFAULT ??' HTH Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiway Branching

2006-01-08 Thread Bengt Richter
A_MAP.get(source.read(2), DEFAULT) > Much better than my version, since you went beyond the OP's code to what he said he was trying to do ("look at two-byte pairs coming from a machine ... over the serial cable"). I just went for a direct translation of the code, which is nearly a

Re: decorator question

2006-01-08 Thread Bengt Richter
ss ... >>> foo() started at Sun Jan 08 14:13:55 2006 ended at Sun Jan 08 14:13:55 2006 diff = 0.00 sec >>> foo() started at Sun Jan 08 14:14:02 2006 ended at Sun Jan 08 14:14:02 2006 diff = 0.00 sec >>> @timelogger() # stdout ... def foo(dt): time.sleep(d

Re: What is the slickest way to transpose a square list of lists (tuple of tuples)?

2006-01-08 Thread Bengt Richter
ith. > OTOH, he's probably just trying to get someone to remember zip-abuse for him. Hope it's not homework ;-) >>> sq = [[r+c for c in 'abc'] for r in '123'] >>> for r in sq: print r ... ['1a', '1b', '1c'] [&#x

Re: Newline at EOF Removal

2006-01-08 Thread Bengt Richter
ystem. You don't need readlines either. Try (untested) # open f and w as before [1] for line in f: if line.strip(): w.write(line) # write only non-blank lines [1] BTW, I didn't see the 't' mode in http://docs.python.org/lib/built-in-funcs.html description of open/file, but I have a nagging doubt about saying it's not valid. Where did you see it? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: is there any lib can split string in this way?

2006-01-08 Thread Bengt Richter
meet my need? > Narrowly interpreting your requirements (only quotes are with double quotes (never containing escaped same) and strip quotes off) and tested only as you see ;-) >>> import re >>> rx = re.compile(r'"([^"]*)"|(\w+)') >>> s = '

Re: itertools.izip brokeness

2006-01-09 Thread Bengt Richter
On 9 Jan 2006 08:19:21 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote: >Op 2006-01-05, Bengt Richter schreef <[EMAIL PROTECTED]>: >> On 5 Jan 2006 15:48:26 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote: [...] >> But you can fix that (only test is what you see

Re: Do you have real-world use cases for map's None fill-in feature?

2006-01-09 Thread Bengt Richter
iteration? Is this a fundamental looping construct or just a >theoretical wish-list item? IOW, does Python really need >itertools.izip_longest() or would that just become a distracting piece >of cruft? Even if there is little use for continuing in correct code, IWT getting at the state of the iterator in an erroroneous situation would be a benefit. Being able to see the result of the last attempt at gathering tuple elements could help. (I can see reasons for wanting variations of trying all streams vs shortcutting on the first to exhaust though). Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-09 Thread Bengt Richter
abstract value, which is always an interpretation of some concrete representation. I suspect that describing things in terms of abstract graphs and their transformations would be useful. E.g., starting with python's objects (in the abstract) as nodes, and "references" as directed arcs. More on this later, perhaps, but I have to go now ... Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Do you have real-world use cases for map's None fill-in feature?

2006-01-10 Thread Bengt Richter
On 10 Jan 2006 00:47:36 -0800, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote: >[Bengt Richter] >> What about some semantics like my izip2 in >> >> http://groups.google.com/group/comp.lang.python/msg/3e9eb63a1ddb1f46?hl=en >> >> (which doe

Re: Augmented generators?

2006-01-10 Thread Bengt Richter
>>> for i in it: ... if i%2: print i, it.value ... 1 b 3 d You could of course store self._value and def value(self):return self._value to be closer to your syntax) >So my question is: Can you think of an easy way to write something that >looks like a generator (using yield), but can also incorporate methods other >than next? > See above. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Augmented generators?

2006-01-10 Thread Bengt Richter
ass DervAugit(AugiterBase): ... def _gen(self, d): ... for k, self._v in d.items(): yield k ... def value(self): return self._v ... >>> it = DervAugit(dict(enumerate('abcd'))) >>> for i in it: ... if i%2: print i, it.value() ... 1 b 3 d >>> for i in it: ... print i, it.value() ... >>> it = DervAugit(dict(enumerate('abcd'))) >>> for i in it: ... print i, it.value() ... 0 a 1 b 2 c 3 d Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: can't solve an exercise-help me with it

2006-01-11 Thread Bengt Richter
t. And sum, if you want a one-liner. Hint2: try 4/7 and 4.0/7 interactively Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Failing unittest Test cases

2006-01-12 Thread Bengt Richter
x27;t belong into the test source. > Perhaps in a config file that can specify special conditions re running identified tests? E.g., don't run vs run and report (warn/fail/info) changed result (e.g. from cached result) vs run and report if pass etc. Then if code change unexpectedly makes a test work, the config file can just be updated, not the test. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I make a dictionary that marks itself when it's modified?

2006-01-12 Thread Bengt Richter
r() values. > You are right, but OTOH the OP speaks of a "flagging" the dict as modified. If she made e.g., "modified" a property of the dict subclass, then retrieving the the "modified" "flag" could dynamically check current state repr vs some prior state rep

Re: More than you ever wanted to know about objects [was: Is everything a refrence or isn't it]

2006-01-12 Thread Bengt Richter
overridden (or instance is of an old-style class as mentioned above). I suspect these then implement the check for __getattr__, which can be user defined to intercept attribute access on particular objects in the search chain, after higher-priority stuff fails. [... Can't ... keep .. eyes ... open ... for ... rest ...] (not the fault of your prose, had a beer ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: flatten a level one list

2006-01-13 Thread Bengt Richter
i) for i in xrange(5)), SI('start:')) Traceback (most recent call last): File "", line 1, in ? TypeError: sum() can't sum strings [use ''.join(seq) instead] vs >>> reduce(operator.__add__, (SI(i) for i in xrange(5)), SI('start:')) 'start:01234' Which seems to boil down to incomplete restrictions on duck typing. Maybe Guido will want to complete it, but ISTM your original implementation delegating string addition implementation to ''.join was reasonable. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to remove subset from a file efficiently?

2006-01-14 Thread Bengt Richter
e hardware can't entirely optimize out with smart buffering etc. Not to mention possible interactions with all the other things an OS may be doing "simultaneously" switching between things that it accounts for as real/user/sys. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursive tree list from dictionary

2006-01-14 Thread Bengt Richter
'Soiltypes', 'parent':'Soil'} ] children = {} for d in source_list: children.setdefault(d['parent'], []).append(d['title']) def get_progeny(title, d=children): if title in d: return [title] + [get_progeny(child) for child in d[title]] else: return title source = ['result_list = ['] result_list = [] for child in children['root']: source.append('# %s'%child) source.append('%r,'% get_progeny(child)) result_list.append(get_progeny(child)) source.append(']') result_list_source = '\n'.join(source) print result_list_source print result_list [18:20] C:\pywk\clp>py24 david_pratt.py result_list = [ # Project ['Project', ['Geometries', ['Geometry', 'Points', 'Layers', 'Water']], 'Verticals'], # Soil ['Soil', 'Soiltypes'], ] [['Project', ['Geometries', ['Geometry', 'Points', 'Layers', 'Water']], 'Verticals'], ['Soil', ' Soiltypes']] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: On Numbers

2006-01-14 Thread Bengt Richter
way of genera modular definition http://www.adaic.org/standards/95lrm/html/RM-3-5-4.html and here is the fixed point http://www.adaic.org/standards/95lrm/html/RM-3-5-9.html Whoo, I haven't been into that stuff almost since Ada was "green" ;-) Makes me wonder if generators could usefully have rendezvous('?, es?) ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Listing partitions (on win32)

2006-01-15 Thread Bengt Richter
if os.popen('dir %s:\\xxx'%c).read()] ... >>> fakeGetLogicalDriveStrings() ['C:', 'D:', 'E:', 'V:', 'W:'] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Listing partitions (on win32)

2006-01-15 Thread Bengt Richter
On Sun, 15 Jan 2006 08:08:16 -0500, "Roger Upole" <[EMAIL PROTECTED]> wrote: > >"Bengt Richter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> On 14 Jan 2006 16:52:33 -0800, "Claude Henchoz" <[EMAIL PROTECTED]> wrote:

Re: instance attributes not inherited?

2006-01-15 Thread Bengt Richter
bject has no attribute 'x' >--- /output - > >Why isn't this inherited method call working right? The method call is working fine. It's just that as before Child.__init__ overrides Parent.__init__ without calling Parent.__init__ or set

Re: proposal: another file iterator

2006-01-16 Thread Bengt Richter
t;for chunk in iter(f.read, '', (blocksize,)): ... > Whatever "Which" refers to got snipped or may be in a post that hasn't become visible for me yet, but I assume Jean-Paul was referring to lambda use as in e.g. (untested): for chunk in iter(lambda frd=open(

Re: instance attributes not inherited?

2006-01-16 Thread Bengt Richter
print 'Inside Parent.__init__()' ... >>> class Child( Parent ): ... def __init__( self ): ... sup = simple_super(self) ... sup.__init__() ... self.sup = sup ... print "Inside Child.__init__()" ... >>> c = Child() Inside Parent.__init__() Inside Child.__init__() >>> c.sup <__main__.simple_super object at 0x02EF80EC> >>> c.sup.__init__ > >>> c.sup.__init__() Inside Parent.__init__() I don't know if this helps ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-16 Thread Bengt Richter
x27;%attr; raise AttributeError ... >>> class B: ... def __getattr__(self, attr): print 'B().%s'%attr; raise AttributeError ... >>> A()==B() A().__eq__ B().__eq__ B().__eq__ A().__eq__ A().__coerce__ B().__coerce__ A().__cmp__ B().__cmp__ False Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-16 Thread Bengt Richter
On Mon, 16 Jan 2006 21:58:26 +1100, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Mon, 16 Jan 2006 10:34:40 +, Bengt Richter wrote: > >> >>> class A: >> ... def __getattr__(self, attr): print 'A().%s'%attr; raise >> AttributeErro

Re: Is 'everything' a refrence or isn't it?

2006-01-16 Thread Bengt Richter
On Mon, 16 Jan 2006 21:58:26 +1100, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Mon, 16 Jan 2006 10:34:40 +, Bengt Richter wrote: > >> >>> class A: >> ... def __getattr__(self, attr): print 'A().%s'%attr; raise >> AttributeErro

Re: Preventing class methods from being defined

2006-01-16 Thread Bengt Richter
on is defined within a factory function). This can be used to advantage sometimes, but needs good documentation to be clear for the next code maintainer ;-) I guess I should re-read your original requirements that led to thes design ideas. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Preventing class methods from being defined

2006-01-17 Thread Bengt Richter
;test from c" ... >>> c = C(True) >>> c.test() Traceback (most recent call last): File "", line 1, in ? File "", line 5, in _null Exception: not allowed to access >>> c2 = C(False) >>> c2.test() test from c >>> vars(c) {'test': >} >>> vars(c2) {} >>> R._restrict ['test'] Still don't know what real application problem this is solving, but that's ok ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Decimal ROUND_HALF_EVEN Default

2006-01-17 Thread Bengt Richter
ath.floor( 5.5)) => 5 Which ISTM is the way some other int conversions have worked, but I can't recall the context ATM. I.e., just trim the fractional bits from the theoretical fixed point twos complement number, which always subtracts those positive-value fractional bits algebraically. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

[OT] Nit: please don't user "it's" unless you can substitute "it is" without changing your inteded meaning.

2006-01-18 Thread Bengt Richter
uot; or it's first letter is "i" ? ;-) And how many "it"s (?) are there in the previous sentence? I wonder if "Eats Leaves and Shoots" (a book on punctuation) has something on that. (vs, "Eats, Leaves, and Shoots" -- panda vs gunslinger). Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Nit: please don't user "it's" unless you can substitute "it is" without changing your inteded meaning.

2006-01-18 Thread Bengt Richter
On 18 Jan 2006 04:19:37 -0800, "Fuzzyman" <[EMAIL PROTECTED]> wrote: > >Bengt Richter wrote: >> Typos happen to all of us, but in case you hadn't realized what "it's" >> is a contraction for ("it is"), now you do, and you can save

Re: OT: excellent book on information theory

2006-01-19 Thread Bengt Richter
you mention that "=" is not "==" in python? I too would resist the idea that assert a*2.5e-8 == x "should be written as" x = a*2.5e-8 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient implementation of deeply nested lists

2006-01-19 Thread Bengt Richter
on that does not recompute the >whole list each time. Any ideas? > Make a custom class factory that makes a class with a1..aN and can be instantiated with x, producing an object that behaves like L So the question in my mind is, how are you actually going to use these "L" things?

Re: Decimal vs float

2006-01-19 Thread Bengt Richter
represented as a float. So is 1.5 and so are more other values than you can count with an ordinary int ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Python code written in 1998, how to improve/change it?

2006-01-20 Thread Bengt Richter
be looking into Pysco or Pyrex and avoid making your >code really unreadable. > How about something like >>> actions = dict( ...a=compile('print "A"; state="b"','','exec'), ...b=compile('print "B"; state="

Re: Decimal vs float

2006-01-23 Thread Bengt Richter
On Sat, 21 Jan 2006 14:28:20 +1100, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Fri, 20 Jan 2006 04:25:01 +, Bengt Richter wrote: > >> On Thu, 19 Jan 2006 12:16:22 +0100, =?ISO-8859-1?Q?Gerhard_H=E4ring?= >> <[EMAIL PROTECTED]> wrote: >> [...] &g

Re: Redirecting standard out in a single namespace

2006-01-23 Thread Bengt Richter
alled from. Then you could give the object initialization parameters as to which namespace you want to have the effect in, and/or methods to control the action or turn it on or off etc. BTW, how about stderr? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Python code written in 1998, how to improve/change it?

2006-01-23 Thread Bengt Richter
On Mon, 23 Jan 2006 08:53:59 +1300, Carl Cerecke <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> On Thu, 19 Jan 2006 23:16:57 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote: > >> How about something like >> >> >>> actions = dict( &

Re: Arithmetic sequences in Python

2006-01-23 Thread Bengt Richter
e classes, functions are functions. classes seem to be classobjs, designed to implement classic class behavior but using the new machinery to achieve compatible integration. > >Admittedly I still confused between the various flavours of functions >(function, bound method, unbound method, class method, static method...) >*wink* but the difference between types and functions is fairly clear. > >Just don't ask about the difference between type and class... *wink* > Why not? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Redirecting standard out in a single namespace

2006-01-24 Thread Bengt Richter
On 23 Jan 2006 04:00:40 -0800, "Fuzzyman" <[EMAIL PROTECTED]> wrote: > >Bengt Richter wrote: > [...] >> It wouldn't be shadowing, but I suppose you could replace sys.stdout with >> a custom object whose methods check where they were called from. >&g

Re: Pulling numbers from ASCII filename not working

2006-01-25 Thread Bengt Richter
= str(Latitude) you probably won't need a print repr(LatString) here if you see the above print >LatInt = int(LatString) >radians = LatInt * 0.0174532925 >zFactor = 1/(113200 * (cos(radians))) > BTW, capitalizing the first letter of python variable names is counter to usual convention. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

<    4   5   6   7   8   9   10   >