Re: Turning an AST node / subnodes into something human-readable

2014-02-19 Thread Dan Goodman
Chris Angelico rosuav at gmail.com writes: I'm working with the ast module to do some analysis on Python codebases, and once I've found what I'm looking for, I want to print something out. The file name I'm hanging onto externally, so that works; and the nodes all have a lineno. So far so

Re: Comparing strings from the back?

2012-09-10 Thread Dan Goodman
On 04/09/2012 03:54, Roy Smith wrote: Let's assume you're testing two strings for equality. You've already done the obvious quick tests (i.e they're the same length), and you're down to the O(n) part of comparing every character. I'm wondering if it might be faster to start at the ends of the

Re: Comparing strings from the back?

2012-09-10 Thread Dan Goodman
On 10/09/2012 18:33, Oscar Benjamin wrote: Computing the hash always requires iterating over all characters in the string so is best case O(N) where string comparison is best case (and often average case) O(1). Yep, but you already have O(N) costs just creating the strings in the first place,

Re: Comparing strings from the back?

2012-09-10 Thread Dan Goodman
On 10/09/2012 18:07, Dan Goodman wrote: On 04/09/2012 03:54, Roy Smith wrote: Let's assume you're testing two strings for equality. You've already done the obvious quick tests (i.e they're the same length), and you're down to the O(n) part of comparing every character. I'm wondering

simple system for building packages for multiple platforms?

2012-02-01 Thread Dan Goodman
Hi all, Until recently, our package has been pure Python, so distributing it has been straightforward. Now, however, we want to add some extension modules in C++. We're happy to provide source only distributions on Linux because almost all Linux users will have all the required compilers and

Re: Terrible FPU performance

2011-04-26 Thread Dan Goodman
Hi, On 26/04/2011 15:40, Mihai Badoiu wrote: I have terrible performance for multiplication when one number gets very close to zero. I'm using cython by writing the following code: This might be an issue with denormal numbers: http://en.wikipedia.org/wiki/Denormal_number I don't know much

Execute bit in .tar.gz file produced by distutils

2011-02-22 Thread Dan Goodman
(i.e. execute bit not set), but I'm not sure if these values are meaningful because they probably don't correspond to any underlying values in the Win 7 file system. Any help much appreciated! Thanks, Dan Goodman -- http://mail.python.org/mailman/listinfo/python-list

Re: Sumatra m/l?

2010-07-10 Thread Dan Goodman
On 10/07/2010 22:08, Neal Becker wrote: Sumatra looks like an interesting project http://pypi.python.org/pypi/Sumatra/0.2 But I have some questions. Is there any mail list or forum? I can't find anything on the website. It's part of Neural Ensemble which has a google group (not specifically

Re: Generating nested code with context managers

2010-05-05 Thread Dan Goodman
I tried a very similar thing, but not using with statements: http://mail.python.org/pipermail/python-list/2010-March/1239577.html Dan On 04/05/2010 22:36, Terry Reedy wrote: In a current thread, people have claimed that generating properly indented nested blocks is a pain because of the need

C++ code generation

2010-03-16 Thread Dan Goodman
Hi all, I'm doing some C++ code generation using Python, and would be interested in any comments on the approach I'm taking. Basically, the problem involves doing some nested loops and executing relatively simple arithmetic code snippets, like: for i in xrange(len(X)): X[i] += 5

Re: Modifying the value of a float-like object

2009-04-15 Thread Dan Goodman
eric.le.bi...@spectro.jussieu.fr wrote: Hello, Is there a way to easily build an object that behaves exactly like a float, but whose value can be changed? The goal is to maintain a list [x, y,…] of these float-like objects, and to modify their value on the fly (with something like x.value =

Re: Modifying the value of a float-like object

2009-04-15 Thread Dan Goodman
eric.le.bi...@spectro.jussieu.fr wrote: I initially tried to create a Float_ref class that inherits from numpy.array, so that objects of the new class behave like numpy.array in calculations, but also contain an uncertainty atribute, but this is apparently not allowed (cannot create

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-26 Thread Dan Goodman
MRAB wrote: Here's my solution (I haven't bothered with making it efficient, BTW): import operator def solve(n): best_len = n best_expr = for x in range(1, n - 2): for y in range(x, n): for op, name in operator_list: # Does this pair with this

Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread Dan Goodman
This sounds kind of similar to a problem I posted to this list last year, you might find that thread gives you some ideas: http://mail.python.org/pipermail/python-list/2008-January/474071.html Dan -- http://mail.python.org/mailman/listinfo/python-list

Re: nth root

2009-01-31 Thread Dan Goodman
Mark Dickinson wrote: I'd also be a bit worried about accuracy. Is it important to you that the integer part of the result is *exactly* right, or is it okay if (n**13)**(1./13) sometimes comes out as slightly less than n, or if (n**13-1)**(1./13) sometimes comes out as n? I don't think

Re: nth root

2009-01-31 Thread Dan Goodman
Mark Dickinson wrote: Well, random numbers is one thing. But how about the following: n = 12345**13 n 154662214940914131102165197707101295849230845947265625L int(n ** (1./13)) # should be 12345; okay 12345 int((n-1) ** (1./13)) # should be 12344; oops! 12345 Good point! Oops indeed.

Re: nth root

2009-01-30 Thread Dan Goodman
Takes less than 1 sec here to do (10**100)**(1./13) a million times, and only about half as long to do (1e100)**(1./13), or about 14 times as long as to do .2**2. Doesn't look like one could hope for it to be that much quicker as you need 9 sig figs of accuracy to get the integer part of