Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-06 Thread David M . Cooke
Martin v. Löwis v.loewis.de> writes: > > This is a good test for Python implementation bottlenecks. Run > > that tokenizer on HTML, and see where the time goes. > > I looked at it with cProfile, and the top function that comes up > for a larger document (52k) is > ...validator.HTMLConformanceCh

Re: setting a breakpoint in the module

2006-08-23 Thread David M. Cooke
pdb.set_trace() at the point you want the debugger to stop. Useful if you want to break after some failing condition, for instance. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Coding style

2006-07-18 Thread David M. Cooke
[EMAIL PROTECTED] (David M. Cooke) writes: > > Bruno's already mentioned that iterators and generators aren't > sequences. Numpy arrays act like the other sequence types: > >>>> a = numpy.array([]) >>>> a > array([], dtype=int64) >>>> le

Re: Coding style

2006-07-18 Thread David M. Cooke
iterators and generators aren't sequences. Numpy arrays act like the other sequence types: >>> a = numpy.array([]) >>> a array([], dtype=int64) >>> len(a) 0 >>> bool(a) False (0-dimensional numpy arrays are pathological anyways) -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: NumPy 0.9.8 released

2006-05-17 Thread David M. Cooke
ipy/numpy/ > > > * numpy should install now with easy_install from setuptools Note that you'll need to use the latest setuptools (0.6b1). The hacks I added to get easy_install and numpy.distutils to get along are hard enough without trying to be backward compatible :-( -- |>|\

Re: "pow" (power) function

2006-03-17 Thread David M. Cooke
e you'd probably want to use numpy. We've optimized x**n so that it does handle n=0.5 and integers specially; it makes more sense to do this for an array of numbers where you can do the special manipulation of the exponent, and then apply that to all the numbers in the array at once. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Python advocacy in scientific computation

2006-03-06 Thread David M. Cooke
Python 2.4 :-) Lost comments and stuff, but the code came out great. -- |>|\/|< /----------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Scientific Computing with NumPy

2006-02-10 Thread David M. Cooke
s installed) it's really to compile: python setup.py build && python setup.py install. Do you need Tiger (10.4) or Panther (10.3) compatibility? -- |>|\/|< /----------\ |David M. Cooke |cookedm(at)physics(dot)mcmas

Re: good library for pdf

2006-01-26 Thread David M. Cooke
li There's also pyPDF, at http://pybrary.net/pyPdf/. I haven't tried it, but it looks interesting. -- |>|\/|< /----------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: idea of building python module using pyrex

2005-12-09 Thread David M. Cooke
r module scipy.random. It's actually used to wrap some C code, but it does the job well. -- |>|\/|< /----------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Underscores in Python numbers

2005-11-19 Thread David M. Cooke
a6 = -0.00019 84090 a8 = 0.0 27526 a10= -0.0 00239 x2 = x**2 return 1. + x2*(a2 + x2*(a4 + x2*(a6 + x2*(a8 + x2*a10 (or least that's what I like to write). Now, if I were going to higher precision, I'd have more digits of course. -- |>|\/|< /-

Re: authentication for xmlrpc via cgi

2005-09-22 Thread David M. Cooke
TY_HOLE_PASS_AUTHORIZATION.html >From what I can see, this is still true in Apache 2. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a way to determine -- when parsing -- if a word contains a builtin name or other imported system module name?

2005-08-04 Thread David M. Cooke
ally an "iskeyword" function there :) For modules, sys.modules is a dictionary of the modules that have been imported. -- |>|\/|< /----------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Annoying behaviour of the != operator

2005-06-10 Thread David M. Cooke
Robert Kern <[EMAIL PROTECTED]> writes: > greg wrote: >> David M. Cooke wrote: >> >>>>To solve that, I would suggest a fourth category of "arbitrary >>>>ordering", but that's probably Py3k material. >>> >>>We've

Re: without shell

2005-06-10 Thread David M. Cooke
orget the one module to rule them all, subprocess: file_list = subprocess.Popen(['ls'], stdout=subprocess.PIPE).communicate()[0] which by default won't use the shell (unless you pass shell=True to it). -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Annoying behaviour of the != operator

2005-06-09 Thread David M. Cooke
y size: [1+2j, 3+4j].sort(key=abs) and since .sort() is stable, for those numbers where the key is the same, the order will stay the same. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: computer algebra packages

2005-06-08 Thread David M. Cooke
's doable. It should also be doable with Maple, using the OpenMaple API. I've looked at it, and it should be possible. I haven't had the time to actually do anything, though :-) -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: editor for shelve files

2005-05-01 Thread David M. Cooke
to handle than the general case. -- |>|\/|< /------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Wrapping c functions

2005-05-01 Thread David M. Cooke
o could be included in the desc field. return PyCObject_FromVoidPtr(dib, NULL) (the NULL can be replaced with a routine that will free the image.) -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a package with convolution and related methods?

2005-04-21 Thread David M. Cooke
/scipy.org) has wraps for FFTW (Fast Fourier Transform in the West). -- |>|\/|< /----------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: python/svn issues....

2005-04-12 Thread David M. Cooke
versioned form, db_create_4002). Running 'nm -D -g' on the libsvn_fs_base library shows it uses the same db_create_4002 function. -- |>|\/|< /--\ |David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/ |[EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: python/svn issues....

2005-04-12 Thread David M. Cooke
/usr/lib/libtasn1.so.2 (0x002a96d1b000) libgcrypt.so.11 => /usr/lib/libgcrypt.so.11 (0x002a96e2b000) libgpg-error.so.0 => /usr/lib/libgpg-error.so.0 (0x002a96f77000) libz.so.1 => /usr/lib/libz.so.1 (0x002a9707b000) If it doesn't look like that, then

Re: Threads and variable assignment

2005-04-12 Thread David M. Cooke
use threads, use a Queue.Queue object where timestamps w/ state changes are pushed on in thread 1, and popped off and analysed before logging in thread 2. (Or something; this just popped in my head.) -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: curious problem with large numbers

2005-04-07 Thread David M. Cooke
you could use >>> import numarray.ieeespecial >>> numarray.ieeespecial.plus_inf inf (there's minus_inf, nan, plus_zero, and minus_zero also) -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: richcmpfunc semantics

2005-04-07 Thread David M. Cooke
objects can fail. If you *know* A and B objects can't be compared for equality, it'd be ok to raise a TypeError, but that should be after a type test. > Also, do you need to increment the reference count > of Py_NotImeplemented before returning it? Yes; it's a singleton like Py_None. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Gnuplot.py and, _by far_, the weirdest thing I've ever seen on my computer

2005-04-04 Thread David M. Cooke
some customization options that might be helpful. In particular, I'd try import Gnuplot Gnuplot.GnuplotOpts.prefer_fifo_data = 0 ... then the data will be save to a temporary file instead of piped through a fifo. Alternatively, try Gnuplot.GnuplotOpts.prefer_inline_data = 1 ... then no file will be used. [I don't use Gnuplot myself; this is just what I came up with after a few minutes of looking at it] -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: numeric module

2005-04-01 Thread David M. Cooke
anything numerical in Python, you'll want them :-) -- |>|\/|< /----------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: numeric module

2005-04-01 Thread David M. Cooke
(): val = testme() wi = int(val >> 4) bi = int(val & 0xF) print wi print bi print tbl[wi,bi] and that'll work. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: itertools to iter transition

2005-03-30 Thread David M. Cooke
true anymore, of course (it was in 2.2.3). In 2.3.5, UserDict, tarfile and some the Mac-specific module use classmethod, and the datetime extension module use the C version (the METH_CLASS flag). And staticmethod (and METH_STATIC) aren't used at all in 2.3 or 2.4 :-) [if you ignore __new__] --

Re: breaking up is hard to do

2005-03-25 Thread David M. Cooke
so makes it easier to know what is a global :-) -- |>|\/|< /------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Using python to extend a python app

2005-03-24 Thread David M. Cooke
ctly this approach, with some extra frills: looking in subdirectories, for instance. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Passing arguments to python from URL

2005-03-22 Thread David M. Cooke
make things easier on yourself; the documentation has a good overview: http://www.python.org/doc/2.4/lib/module-cgi.html In this case, your script would look something like this: import cgi form = cgi.FieldStorage() if form.getvalue('sort') == 'ascending': ... sort in asce

Re: how to handle repetitive regexp match checks

2005-03-17 Thread David M. Cooke
r: def __init__(self, text): self.m = None self.text = text def match(self, pat): self.m = pat.match(self.text) return self.m def __getitem__(self, name): return self.m.group(name) Then, use it like for line in fo: m = Matcher(line) if m.matc

Re: SAX parsing problem

2005-03-15 Thread David M. Cooke
t;, "&", and "%20value"? The xml.sax.handler.ContentHandler.characters method (which I presume you're using for SAX, as you don't mention!) is not guaranteed to get all contiguous character data in one call. Also check if .skippedEntity() methods are firing. -- |>

Re: binutils "strings" like functionality?

2005-03-03 Thread David M. Cooke
m. Are you sure it's monkey/chicken/dog/cat, and not monkey\chicken\dog\cat? The later one will print monkey\\chicken... because of the repr() call. Also, you probably want it as [\x20-\x7e] (the DEL character \x7f isn't printable). You're also missing tabs (\t). The

Re: How to write python plug-ins for your own python program?

2005-03-03 Thread David M. Cooke
the name of the python file, minus the ".py" extension. You'd better hope someone doesn't name their plugin 'os; os.system("rm -rf /"); import sys' Use __import__ instead. -- |>|\/|< /--

Re: [ANN] Python 2.4 Quick Reference available

2005-02-19 Thread David M. Cooke
is more suited to type testing (for example, writing "isinstance(f, file)"). """ ... which more accurately reflects what I believe the consensus is about the usage of open vs. file. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: LinearAlgebra incredibly slow for eigenvalue problems

2005-01-28 Thread David M. Cooke
27;s linked, then it's not being installed right. You don't have a previous Numeric installation that's being picked up instead of the one you're trying to install, do you? At the interpreter prompt, check that >>> import Numeric >>> Numeric.__file_

Re: LinearAlgebra incredibly slow for eigenvalue problems

2005-01-28 Thread David M. Cooke
, and set some directories) Also set use_dotblas to 1. - do the 'python setup.py build', 'python setup.py install' dance. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: MMTK Install Problem

2005-01-26 Thread David M. Cooke
st version is 23.7. It should be real easy to upgrade to that, as that version picks up Apple's vecLib framework for the linear algebra routines. Just do the usual 'python setup.py build', 'sudo python setup.py install'. That should put the header files where the MMTK install

Re: pickling extension class

2005-01-18 Thread David M. Cooke
^ I think that's your error. The extension type is declared to be hyper.PeriodicGrid, where it actually is model.hyper.PeriodicGrid (because hyper is in the model package). Pickle stores g.__class__.__module__ (which is "hyper") and g.__class__.__name__ (="PeriodicGrid") to find the class object for reimporting, and on unpickling, tries to do __import__("hyper"), which fails. The tp_name slot of your extension type should be "model.hyper.PeriodicGrid". -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Pyrex-0.9.3: definition mismatch with distutils of Python24

2005-01-13 Thread David M. Cooke
rted a few times. You'll want to change it to def swig_sources(self, sources, extension=None): so that if you use an older python it won't complain about missing arguments. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: OT: MoinMoin and Mediawiki?

2005-01-11 Thread David M. Cooke
page. Searching instead of indexing makes it very resilient :-) -- |>|\/|< /----------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: readline, rlcompleter

2005-01-11 Thread David M. Cooke
unction keys would have to be specified as the key sequence sent by a function key ("\e[11~" for F1, for instance). Have a look at the readline info page, or the man page. The syntax of readline.parse_and_bind is the same as that of an inputrc file. -- |>|\/|< /-

Re: Python3: on removing map, reduce, filter

2005-01-10 Thread David M. Cooke
uot; 1000 loops, best of 3: 464 usec per loop $ python2.4 -m timeit "[x*x for x in range(1000)]" 1000 loops, best of 3: 216 usec per loop So factor of 2, instead of 13700 ... -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: why not datetime.strptime() ?

2005-01-10 Thread David M. Cooke
"(like time.strptime()).")}, > + > {"combine", (PyCFunction)datetime_combine, >METH_VARARGS | METH_KEYWORDS | METH_CLASS, >PyDoc_STR("date, time -> datetime with same date and time fields")}, It probably would help to add some documentation to add to the datetime module documentation. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: date/time

2005-01-05 Thread David M. Cooke
ime tt = time.strptime('20041231', '%Y%m%d') t = datetime.date.fromtimestamp(time.mktime(tt)) # now in a easier-to-handle form than the time tuple t += datetime.timedelta(days=1) print t.strftime('%Y%m%d') -- |>|\/|< /-

Re: getattr() woes

2004-12-28 Thread David M. Cooke
is if getattr, when raising AttributeError, somehow reused the old traceback (which would point out the original problem). I don't know how to do that, though. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Namespaces and the timeit module

2004-12-14 Thread David M. Cooke
py), then, from the command line: $ python -m timeit -s 'from x import foo' 'foo()' (the -m is for python 2.4 to run the timeit module; use the full path to timeit.py instead for earlier pythons) Alternatively, the examples for the timeit module has another way to time functions defined in a module. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list

Re: Distutils vs. Extension header files

2004-12-10 Thread David M. Cooke
luding depends, data files, and other stuff you'd think it would do. When in doubt, add it to MANIFEST.in. -- |>|\/|< /--\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca -- http://mail.python.org/mailman/listinfo/python-list