Re: web.py & postgresql error

2007-10-23 Thread Adam Atlas
On Oct 22, 9:06 pm, [EMAIL PROTECTED] wrote: > hi everyone, i'm very new to python and to this forum. i'm actually > just trying to work through the tutorial on webpy.org. so far, so > good, but as i tried to incorporate a postgresql database into the > demo web app i'm receiving this error print

Re: Python - why don't this script work?

2007-10-22 Thread Adam Atlas
On Oct 22, 9:47 pm, Ohmster <[EMAIL PROTECTED]> wrote: > I am trying to use this cool script that some MIT guy wrote and it just > does not work, I get a stream of errors when I try to run it. It is > supposed to visit a URL and snag all of the pictures on the site. Here is > the script:http://web.

Re: Convert string to command..

2007-10-18 Thread Adam Atlas
On Oct 18, 10:23 am, Abandoned <[EMAIL PROTECTED]> wrote: > I want to convert a string to command.. > For example i have a string: > a="['1']" > I want to do this list.. > How can i do ? Use the builtin function "eval". -- http://mail.python.org/mailman/listinfo/python-list

Re: Noob questions about Python

2007-10-17 Thread Adam Atlas
On Oct 17, 3:37 pm, Ixiaus <[EMAIL PROTECTED]> wrote: > I have recently (today) just started learning/playing with Python. So > far I am excited and impressed (coming from PHP background). > > I have a few questions regarding Python behavior... > > val = 'string' > li = list(val) > print li.reverse

Re: Python on imac

2007-10-13 Thread Adam Atlas
On Oct 13, 7:21 pm, John Velman <[EMAIL PROTECTED]> wrote: > I'm considering moving from Linux to imac. I've recently returned to > Python (was never very expert) to develop a small gui application. At > present I plan to use PyGTK with Pango and Cairo. > > What surprises may I be in for :-) > >

Python process automatically restarting itself

2007-10-11 Thread Adam Atlas
What is the best way for a Python process (presumed to be a script run by the interpreter binary, not embedded in some other program) to restart itself? This is what I've been trying: import __main__ for path in sys.path: path += '/' + __main__.__file__ if os.access(path,

Plugging a pseudo-memory leak

2007-07-03 Thread Adam Atlas
I have a program that seemed to be leaking memory, but after debugging, it seemed it just wasn't getting around to collecting the objects in question often enough. The objects are very long-lived, so they probably end up in generation 2, and don't get collected for a long time. Is there any way I c

PyKQueue

2007-06-26 Thread Adam Atlas
Does anyone have a copy of PyKQueue 2.0 around? The site it's supposed to be on (http://python-hpio.net/trac/wiki/PyKQueue) is down. -- http://mail.python.org/mailman/listinfo/python-list

Re: How do you htmlentities in Python

2007-06-04 Thread Adam Atlas
As far as I know, there isn't a standard idiom to do this, but it's still a one-liner. Untested, but I think this should work: import re from htmlentitydefs import name2codepoint def htmlentitydecode(s): return re.sub('&(%s);' % '|'.join(name2codepoint), lambda m: name2codepoint[m.group(1)], s

Re: `yield` in a `try/finally` block, pre-Python 2.5

2007-06-04 Thread Adam Atlas
On Jun 4, 1:49 am, yuce <[EMAIL PROTECTED]> wrote: > I had the same problem, you can > see:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/130004 > for a solution. > > Happy hacking, > > Yuce Thanks. I thought of doing something like that, but in my program, it's important that the order

`yield` in a `try/finally` block, pre-Python 2.5

2007-06-03 Thread Adam Atlas
I'm trying to emulate the Python 2.5 behaviour (PEP 342) of generator functions where the `yield` statement is in a `try/finally` block. Basically, where the `finally` block is guaranteed to run even if the generator doesn't finish running: it simply runs when the generator is garbage-collected. Do

Re: How to cleanly pause/stop a long running function?

2007-05-12 Thread Adam Atlas
On May 12, 4:51 pm, Basilisk96 <[EMAIL PROTECTED]> wrote: > Suppose I have a function that may run for a long time - perhaps from > several minutes to several hours. An example would be this file > processing function: > > import os > def processFiles(startDir): > for root, dirs, files in os.wa

Re: Newbie question about string(passing by ref)

2007-05-10 Thread Adam Atlas
On May 10, 6:19 pm, lazy <[EMAIL PROTECTED]> wrote: > So, just to make sure even if I return a value, there is no copy done. > Is it correct? > For eg: > > def blah: >long_str="" >return long_str > > my_str=blah() <=== So here there is no copy done but, my_str points to > the same memor

Re: Newbie question about string(passing by ref)

2007-05-10 Thread Adam Atlas
On May 10, 5:47 pm, Adam Atlas <[EMAIL PROTECTED]> wrote: > On May 10, 5:43 pm, lazy <[EMAIL PROTECTED]> wrote: > > > I want to pass a string by reference. > > Don't worry, all function parameters in Python are passed by reference. Actually, just to clarify a

Re: Newbie question about string(passing by ref)

2007-05-10 Thread Adam Atlas
On May 10, 5:43 pm, lazy <[EMAIL PROTECTED]> wrote: > I want to pass a string by reference. Don't worry, all function parameters in Python are passed by reference. -- http://mail.python.org/mailman/listinfo/python-list

WSGI spec clarification regarding exceptions

2007-05-09 Thread Adam Atlas
I'm trying to figure out if there's any defined behaviour in PEP 333 for instances where an application returns an iterable as usual without error, but that iterable's next() method eventually raises an exception. Since any data theretofore returned by the iterable must be assumed to have already b

Re: __dict__s and types and maybe metaclasses...

2007-05-02 Thread Adam Atlas
On May 2, 5:24 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > I think that most people accomplish this by: > > class blah: > __initial_values={'a': 123, 'b': 456} > > def __init__(self): > self.__dict__.update(self.__initialvalues) That's not really what I'm talking about... I'm talk

Re: Can I use Python instead of Joomla?

2007-05-02 Thread Adam Atlas
On May 2, 4:48 pm, walterbyrd <[EMAIL PROTECTED]> wrote: > If I wanted to build a website with forums, news feeds, galleries, > event calander, document managment, etc. I do so in Joomla easily. > > But, I would perfer to use django/python, if that would be at all > practical. > > I suppose I could

__dict__s and types and maybe metaclasses...

2007-05-02 Thread Adam Atlas
Suppose I want to create a type (i.e. a new-style class via the usual `class blah(...)` mechanism) but, during the process of creating the type, I want to replace its __dict__ so I can override some behaviors during the initial assignment of its members. That is, I have `class blah(...): a = 123; b

Re: editing scripts on a mac

2007-04-29 Thread Adam Atlas
On Apr 27, 12:08 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Now, frankly, I don't think this answer is correct, since I know OS X is > a UNIX derivative, but I am loathe to involve a programming noob with vi > or something similar. So I wondered if one of the c.l.py mac users could > give brief

Tracebacks for `exec`ed code?

2007-04-28 Thread Adam Atlas
Is it possible to make more traceback information available for exceptions code dynamically run via `exec`? Normally it just says things like "File '', line 3, in ?", which is not very helpful. I'm looking for a way for it to show the line of source code below it, like it would for an exception in

Re: Python for Vcard Parsing in UTF16

2007-04-24 Thread Adam Atlas
On Apr 21, 7:28 pm, R Wood <[EMAIL PROTECTED]> wrote: > To me this was a natural task for Perl. Turns out however, there's a catch. > Apple exports the file in UTF-16 to ensure anyone with Chinese characters in > their addressbook gets a legitimate Vcard file. Here's a function that, given a `s

Re: Python for Vcard Parsing in UTF16

2007-04-24 Thread Adam Atlas
On Apr 21, 7:28 pm, R Wood <[EMAIL PROTECTED]> wrote: > I know nothing about Python except that it interests me and has interested me > since I first learned the Rekall database frontend (Linux) runs on it. I just > ordered Learning Python and if that works out satisfactorily I'm going to go > bac

Re: Better dict of dicts

2007-04-19 Thread Adam Atlas
On Apr 19, 5:24 pm, Bill Jackson <[EMAIL PROTECTED]> wrote: > I have a dictionary of dictionaries where the keys are typically very > long tuples and repeated in each inner dictionary. The dictionary > representation is nice because it handles sparseness well...and it is > nice to be able to look

Re: Compare regular expressions

2007-04-16 Thread Adam Atlas
On Apr 16, 1:50 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > It's not. For the simplest of expressions one might come up with a > relation between them, but even that would be hard. General case? No chance. I wouldn't say there's 'no chance'. It would require external parsing, for sure, but

Re: Breaking up Strings correctly:

2007-04-09 Thread Adam Atlas
On Apr 9, 8:19 am, "Michael Yanowitz" <[EMAIL PROTECTED]> wrote: > Hello: > >I have been searching for an easy solution, and hopefully one > has already been written, so I don't want to reinvent the wheel: Pyparsing is indeed a fine package, but if Paul gets to plug his module, then so do I! :

Re: RFC: Assignment as expression (pre-PEP)

2007-04-09 Thread Adam Atlas
Hasn't this been discussed many many times before? I think Guido has been favourable to the idea of allowing :=, but that was a long time ago, and I don't think anything ever came of it. Personally, if anything, I'd like to see more use of the 'as' keyword as in Python 2.5's new 'with' statement.

Re: Python C extension providing... Python's own API?

2007-03-26 Thread Adam Atlas
Wow! I'll have to read through that tomorrow when I'm (hopefully) less tired. :D Anyway, I somehow already managed to get this working. I'm calling it DoublePy. Here's the alpha or proof-of-concept or whatever we're to call it. http://adamatlas.org/2007/03/doublepy-0.1.tar.gz Not bad for an 0.1 w

Re: Python C extension providing... Python's own API?

2007-03-26 Thread Adam Atlas
On Mar 26, 4:55 pm, "Matimus" <[EMAIL PROTECTED]> wrote: > I think that is what the "code" module is for. Maybe not exactly what > you were expecting, but the capability you describe is already there. > Being able to access its own interpreter is one of the things that > makes Python a dynamic lan

Python C extension providing... Python's own API?

2007-03-26 Thread Adam Atlas
Does anyone know if it would be possible to create a CPython extension -- or use the ctypes module -- to access Python's own embedding API (http://docs.python.org/api/initialization.html &c.)? Could a Python program itself create a sub-interpreter, and work with it with all the privileges and capab

[ANN] squisher 0.3

2007-03-17 Thread Adam Atlas
http://cheeseshop.python.org/pypi/squisher/0.3 I've posted the third version of my experimental packaging program Squisher. Squisher can take a directory representing a Python package (i.e. a directory with __init__.py) and "squish" it into a single .pyc file that you can import, or run on the com

Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-06 Thread Adam Atlas
I updated it. http://adamatlas.org/2007/03/Squisher-0.2.py New Things: - It supports C extensions within squished packages. - It supports including squished packages within other squished packages. (That is, you can have a package that includes a .pyc generated by this, and turn that whole package

Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-06 Thread Adam Atlas
Doesn't seem to work. I guess zipimport doesn't support that by default... but if I remember correctly, Setuptools adds that. Maybe I'll take a look at how it does it (I think by extracting the .so to / tmp?) and see how easy it would be to integrate it here. -- http://mail.python.org/mailman/lis

Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-05 Thread Adam Atlas
Okay, here's the prototype... It's meant to be run as a command line program (pass it a directory or a zip file as an argument). By default it will save the new file to the argument's base name plus '.pyc'. You can override this with -o. Obviously it'

Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-05 Thread Adam Atlas
Ah... heh, sorry, I misread your message as "a much more convenient way" rather than "much more than a convenient way". Anyway, I understand that, and I do indeed find setuptools useful and use it on a regular basis. But my other points still stand. This would be a moot point if setuptools were pa

Re: Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-05 Thread Adam Atlas
This could be easily made into a distutils extension (which was my intention all along, though that's not implemented yet). That's not the point. This is not intended as a "way to package source code". It's analogous to bdist, not sdist. The convenience gain is for the users, not (primarily) the de

Squisher -- a lightweight, self-contained alternative to eggs?

2007-03-04 Thread Adam Atlas
I wrote this little program called Squisher that takes a ZIP file containing Python modules and generates a totally self-contained .pyc file that imports a specified module therein. (Conveniently, Python's bytecode parser ignores anything after an end marker, and the zipimport mechanism skips any n

Re: Announcement -- ZestyParser

2007-01-11 Thread Adam Atlas
Thanks for the responses; you're right, and I have now posted the examples online. I just released version 0.6.0, by the way, which has several worthwhile improvements and much better documentation. It also includes an example for parsing RDF Notation3, to demonstrate a parsing task a bit more comp

Announcement -- ZestyParser

2007-01-09 Thread Adam Atlas
This has been on Cheese Shop for a few weeks now, being updated now and then, but I never really announced it. I just now put up a real web page for it, so I thought I'd take the opportunity to mention it here. ZestyParser is my attempt at a flexible toolkit for creating concise, precise, and Pyth

Re: Getting the name of an assignment

2006-12-23 Thread Adam Atlas
Thanks, Steven and Steven. @Bethard: Isn't it a bit convoluted to use metaclasses? someinstance.__class__.__name__ does the same thing. @D'Aprano: Thanks for the advice to rethink my data model. I'm doing so right now, and I've already come up with a way that makes more sense. :) -- http://mail

Re: Getting the name of an assignment

2006-12-23 Thread Adam Atlas
On Dec 23, 5:58 pm, "BJörn Lindqvist" <[EMAIL PROTECTED]> wrote: > On 23 Dec 2006 14:38:19 -0800, Adam Atlas <[EMAIL PROTECTED]> wrote: > > > Is it possible for an object, in its __init__ method, to find out if it > > is being assigned to a variable, and if

Getting the name of an assignment

2006-12-23 Thread Adam Atlas
Is it possible for an object, in its __init__ method, to find out if it is being assigned to a variable, and if so, what that variable's name is? I can think of some potentially ugly ways of finding out using sys._getframe, but if possible I'd prefer something less exotic. (Basically I have a class

Re: Multiple (threaded?) connections to BaseHTTPServer

2005-08-23 Thread Adam Atlas
Never mind... I've found a workable solution: http://mail.python.org/pipermail/python-list/2001-August/062214.html Robert, thanks, I'll still check that out for any future projects; but for my current purpose, it seems overkill. But I don't know for sure; assuming BaseHTTPServer is good enough for

Multiple (threaded?) connections to BaseHTTPServer

2005-08-23 Thread Adam Atlas
Is there any built-in way for BaseHTTPServer to handle multiple connections at once, e.g. with threads? If not, can this existing module be easily extended to do this, or will I have to do lower-level socket things (and probably thus have to write my own HTTP code)? Thanks. Adam -- http://mail.