Hygenic Macros
Hi, Just wondering if anyone has considered macros for Python. I have one good use case. In "R", the statistical programming language, you can multiply matrices with A %*% B (A*B corresponds to pointwise multiplication). In Python, I have to type import Numeric matrixmultiply(A,B) which makes my code almost unreadable. Thanks, David -- http://mail.python.org/mailman/listinfo/python-list
Re: Hygenic Macros
Hi, Thanks - this cookbook entry is very cool! I am somewhat worried about function call overhead from the infix hack though... on second consideration, the infix issue is not as important as eventually boosting the speed of the inner loop to which matrixmultiply() belongs. For those who are interested in things like fast math, I found http://www.scipy.org/documentation/weave/weaveperformance.html very eye-opening. For many of the examples cited there, it is possible to simply treat the source as a string and then do the necessary macro transformations before passing it off to a compiler... David Robert Kern wrote: > David Pokorny wrote: > >>Hi, >> >>Just wondering if anyone has considered macros for Python. I have one >>good use case. In "R", the statistical programming language, you can >>multiply matrices with A %*% B (A*B corresponds to pointwise >>multiplication). In Python, I have to type >> >>import Numeric >>matrixmultiply(A,B) >> >>which makes my code almost unreadable. > > > Well, dot(A, B) is better. But if you must: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 > -- http://mail.python.org/mailman/listinfo/python-list
Restricted Execution on the cheap
Hi, Suppose that one wants to set up a machine to accept python code from, say, arbitrary email, and run it safely. Would the following (somewhat draconian) precautions be sufficient? [assume the Python code is in hack.py] grep exechack.py ==> nothing grep evalhack.py ==> nothing etc... for 'import', 'builtin', 'globals','reload' 'compile', 'file', 'open', 'input', 'locals', 'vars' Furthermore, suppose that along with the daemon that processes the the email there is in addition a watcher daemon that kills and restarts the email-python-runner under any of the following conditions: stdout > 50 MB email-python-runner's heap is > 50 MB email-python-runner gets stuck on a single program for more than 5 minutes If you're interested in hacking such a device, I'm sorry to disappoint --- it won't be up for a long time. Thanks! David Pokorny -- http://mail.python.org/mailman/listinfo/python-list