Re: [Twisted-Python] Counting errors in a DeferredList and avoiding Unhandled error in Deferred messages

2008-05-05 Thread Terry Jones
Hi Jean-Paul You can do this (if you replace `pass´ with `None´, anyway) or you can pass `consumeErrors=True´ to the `DeferredList´ initializer which will make it do something equivalent. Thanks. Sorry - I should have just read the docs again :-) Terry --

Re: Global variables in modules...

2008-03-28 Thread Terry Jones
Peter == Peter Otten [EMAIL PROTECTED] writes: Peter [EMAIL PROTECTED] wrote: [snip] ...can someone explain why invoking a.py prints 0? I would have thought that the global variable 'g' of module 'a' would be set to 1... Peter When you run a.py as a script it is put into the sys.modules

Question on using distutils.core.run_setup

2008-03-17 Thread Terry Jones
I'm trying to programmatically install something built using distutils. I found distutils.core.run_setup and can use it via dist = run_setup('setup.py', ['-q', 'install']) Is that the recommended way to do an install from inside Python (as opposed to doing it on the command line)? If so, how

Re: European python developers

2008-02-26 Thread Terry Jones
Hi Jerry I am hoping one or two members of this list might help me locate in Europe Do you mean you want to re-locate here or that you're trying to locate (i.e., find) people already here? My personal first choice is Spain I'm in Barcelona (but not looking for work!). There are a couple of

Re: flattening a dict

2008-02-17 Thread Terry Jones
Hi Arnaud Benjamin Here's a version that's a bit more general. It handles keys whose values are empty dicts (assigning None to the value in the result), and also dict keys that are not strings (see the test data below). It's also less recursive as it only calls itself on values that are dicts.

Re: flattening a dict

2008-02-17 Thread Terry Jones
Arnaud == Arnaud Delobelle [EMAIL PROTECTED] writes: Arnaud BTW, I keep using the idiom itertools.chain(*iterable). I guess Arnaud that during function calls *iterable gets expanded to a tuple. Arnaud Wouldn't it be nice to have an equivalent one-argument function Arnaud that takes an iterable

Re: type, object hierarchy?

2008-02-03 Thread Terry Jones
Arnaud == Arnaud Delobelle [EMAIL PROTECTED] writes: Arnaud Are you suggesting a new axiom for propositional logic: Arnaud ((P = Q) ^ (R = Q)) = (P = R) ? Arnaud I.e. in fruit logic: every orange is a fruit and every apple is a Arnaud fruit, therefore every orange is an apple. This is

Re: Just for fun: Countdown numbers game solver

2008-01-25 Thread Terry Jones
My output looks better sorted. I.e., for s in sorted(solutions)... Giving the easier to read/compare: Target 234, numbers = (100, 9, 7, 6, 3, 1) (6, 1, 'add', 100, 'mul', 7, 'sub', 9, 'add', 3, 'div') (6, 9, 'sub', 7, 'mul', 1, 'sub', 100, 'add', 3, 'mul') (7, 3, 'mul',

Re: Text-based data inspector for Python?

2008-01-24 Thread Terry Jones
kj == kj [EMAIL PROTECTED] writes: kj I've only recently started programming in Python, trying to wean kj myself from Perl. One of the things I *really* miss from Perl is kj a 100% mouse-free data inspector, affectionally known as the Perl kj debugger, PerlDB, or just perl -d. With it I can

Re: Just for fun: Countdown numbers game solver

2008-01-23 Thread Terry Jones
Hi Arnaud and Dan Arnaud == Arnaud Delobelle [EMAIL PROTECTED] writes: What was wrong with the very fast(?) code you sent earlier? Arnaud I thought it was a bit convoluted, wanted to try something I Arnaud thought had more potential. I think the problem with the second Arnaud one is that I

Re: Just for fun: Countdown numbers game solver

2008-01-23 Thread Terry Jones
Arnaud == Arnaud Delobelle [EMAIL PROTECTED] writes: Arnaud FWIW, I have a clear idea of what the space of solutions is, and Arnaud which solutions I consider to be equivalent. I'll explain it Arnaud below. I'm not saying it's the right model, but it's the one Arnaud within which I'm thinking.

Re: Just for fun: Countdown numbers game solver

2008-01-23 Thread Terry Jones
Arnaud == Arnaud Delobelle [EMAIL PROTECTED] writes: Ha - you can't have it both ways Arnaud! You don't want the computation to go negative... doesn't that (and my proof) have something to do with the inverse nature of add and sub? :-) Arnaud I think I can have it both ways, here's why: the

Re: Just for fun: Countdown numbers game solver

2008-01-22 Thread Terry Jones
Hi Arnaud I've tried a completely different approach, that I imagine as 'folding'. I thought it would improve performance over my previous effort but extremely limited and crude benchmarking seems to indicate disappointingly comparable performance... I wrote a stack-based version yesterday

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Terry Jones
Arnaud == Arnaud Delobelle [EMAIL PROTECTED] writes: Arnaud In countdown you are not required to use all numbers to reach the Arnaud target. This means you are missing solutions, e.g. (1, 3, 6, Arnaud 'mul', 'add', 7 , 'add', 9, 'mul') Hi Arnaud. Thanks, I didn't know that. The fix is a

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Terry Jones
Paul == Paul Rubin http://phr.cx@NOSPAM.invalid writes: Hi Paul Paul Here's my latest, which I think is exhaustive, but it is very slow. Paul It prints a progress message now and then just to give the user some Paul sign of life. It should print a total of 256-8 = 248 of those Paul messages

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Terry Jones
dg == dg google groups [EMAIL PROTECTED] writes: dg It's great how many different sorts of solutions (or almost solutions) dg this puzzle has generated. Speedwise, for reference my solution posted dg above takes about 40 seconds on my 1.8GHz laptop, and the less elegant dg version (on my webpage

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Terry Jones
cokofreedom == cokofreedom [EMAIL PROTECTED] writes: cokofreedom Terry, your technique is efficient and pretty readable! All cokofreedom that could be added now is a way to output the data in a more cokofreedom user-friendly print. Yes, and a fix for the bug Arnaud just pointed out :-) Below

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread Terry Jones
Arnaud == Arnaud Delobelle [EMAIL PROTECTED] writes: Arnaud Sorry I gave an incorrect example to illustrate my question last Arnaud night (I blame this on baby-induced sleep deprivation ;), so I'll Arnaud have another go: Arnaud Say I have 2, 3, 4, 100 and I want to make 406. AFAICS there is

Re: Just for fun: Countdown numbers game solver

2008-01-20 Thread Terry Jones
Here's a solution that doesn't use any copying of lists in for recursion. It also eliminates a bunch of trivially equivalent solutions. The countdown function is 37 lines of non-comment code. Sample (RPN) output below. Terry from operator import * def countdown(target, nums, numsAvail, value,

Re: writing Python in Emacs

2008-01-19 Thread Terry Jones
Richard == Richard Szopa [EMAIL PROTECTED] writes: Richard I am a devoted Emacs user and I write a lot in Python. Me too. Richard I need the following features: Richard 1) Tab completion, ideally Slime like. That is, when there's not Richard enough letters to unambiguously complete a symbol,

RE: Some Berkeley DB questions (being maintained? queries?)

2008-01-17 Thread Terry Jones
Brian == Brian Smith [EMAIL PROTECTED] writes: Brian [EMAIL PROTECTED] wrote: 2. Are there good python libraries for bdb available, that are being maintained? Brian I would like to know the answer to this question too--if you have Brian used the pybsddb/bsddb.db module, please share your

Re: Open a List of Files

2008-01-09 Thread Terry Jones
Fredrik == Fredrik Lundh [EMAIL PROTECTED] writes: Fredrik Seriously, for a limited number of files, the dictionary approach Fredrik is mostly pointless; you end up replacing Fredrik foo = open(foo) Fredrik foo.write(...) Fredrik with Fredrik somedict[foo] = open(foo) Fredrik

Re: Open a List of Files

2008-01-09 Thread Terry Jones
BJ == BJ Swope [EMAIL PROTECTED] writes: I (at least) think the code looks much nicer. BJ #Referring to files to write in various places... BJ open_files['deliveries'].write(flat_line) BJ open_files['deliveries'].write('\n') If you were doing a lot with the deliveries file at some point, you

Re: Open a List of Files

2008-01-08 Thread Terry Jones
Hi BJ Fredrik Lundh [EMAIL PROTECTED] writes: Or in a dict: open_files = {} for fn in ['messages', 'recipients', 'viruses']: open_files[fn] = open(getfilename(fn), 'w') I decided that I was just trying to be too smooth by 1/2 so I fell back to ... messages =

Re: Two candies

2008-01-02 Thread Terry Jones
Raymond == Raymond Hettinger [EMAIL PROTECTED] writes: Raymond * in most apps (except for sparse arrays), the initialization time Raymond for an array is dominated by the time spent actually doing Raymond something useful with the array (iow, this is an odd place to be Raymond optimizing) This

Re: getting n items at a time from a generator

2007-12-29 Thread Terry Jones
Hi Igor Igor == Igor V Rafienko [EMAIL PROTECTED] writes: Also consider this solution from O'Reilly's Python Cookbook (2nd Ed.) p705 def chop(iterable, length=2): return izip(*(iter(iterable),) * length) Igor Is this *always* guaranteed by the language to work? Should the Igor iterator

Re: getting n items at a time from a generator

2007-12-27 Thread Terry Jones
Kugutsumen == Kugutsumen [EMAIL PROTECTED] writes: Kugutsumen On Dec 27, 7:07 pm, Paul Hankin [EMAIL PROTECTED] wrote: On Dec 27, 11:34 am, Kugutsumen [EMAIL PROTECTED] wrote: I am relatively new the python language and I am afraid to be missing some clever construct or built-in way

Re: Taxicab Numbers

2007-12-27 Thread Terry Jones
rgalgon == rgalgon [EMAIL PROTECTED] writes: rgalgon I'm new to Python and have been putting my mind to learning it rgalgon over my holiday break. I've been looking over the functional rgalgon programming aspects of Python and I'm stuck trying to come up with rgalgon some concise code to find

Re: How to generate pdf file from an html page??

2007-12-19 Thread Terry Jones
Grant == Grant Edwards [EMAIL PROTECTED] writes: Grant On 2007-12-19, abhishek [EMAIL PROTECTED] wrote: Hi everyone, I am trying to generate a PDF printable format file from an html page. Is there a way to do this using python. If yes then which library and functions are required and if no

Re: Finding overlapping times...

2007-12-13 Thread Terry Jones
Hi Breal I have a list that looks like the following [(10, 100010), (15, 17), (19, 100015)] I would like to be able to determine which of these overlap each other. So, in this case, tuple 1 overlaps with tuples 2 and 3. Tuple 2 overlaps with 1. Tuple 3 overlaps with

Re: Speed of Nested Functions Lambda Expressions

2007-12-07 Thread Terry Jones
Duncan == Duncan Booth [EMAIL PROTECTED] writes: Duncan Terry Jones [EMAIL PROTECTED] wrote: Duncan Booth wrote: Duncan You'll kick yourself for not seeing it. Duncan If you changed fn_inner to: Duncan def fn_inner(): Duncan a, v = v, a Duncan then you also changed 'a' and 'v' into local

Re: Speed of Nested Functions Lambda Expressions

2007-12-06 Thread Terry Jones
in the containing function. I'd be happy to know how/when this happens. I know I probably shouldn't care, but I do. Thanks, Terry Jones -- http://mail.python.org/mailman/listinfo/python-list