[Tutor] Accesing "column" of a 2D list

2007-08-20 Thread Orest Kozyar
I've got a "2D" list (essentially a list of lists where all sublists are of the same length). The sublists are polymorphic. One "2D" list I commonly work with is: [ [datetime object, float, int, float], [datetime object, float, int, float], [datetime object, float, int, float] ] I'd like to

[Tutor] Variable scope for class?

2007-08-30 Thread Orest Kozyar
I'm trying to follow the example listed in the wiki at http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject regarding the use of a metaclass. What I don't understand is how the metaclass (EntitySingleton) has access to the variable ctx which is instantinated outside the scope of the cla

[Tutor] Metaclass programming

2007-09-03 Thread Orest Kozyar
I have the following code: class meta(type): def __call__(cls, *args, **kwargs): argnames = inspect.getargspec(cls.__init__)[0] for i, value in enumerate(args): kwargs[argnames[i]] = value return type.__call__(cls, kw

Re: [Tutor] Metaclass programming

2007-09-04 Thread Orest Kozyar
> This could be written >kwargs.update(zip(argnames, args)) Nice trick! Thanks for the pointer. > > return type.__call__(cls, kwargs) > > You are passing kwargs as a positional argument to __call__(); i.e. > passing the dict as an ordinary parameter. To use kwargs as > the

[Tutor] evaluating AND

2007-09-13 Thread Orest Kozyar
Given a variable x that can either be None or a tuple of two floats [i.e. (0.32, 4.2)], which syntax is considered most appropriate under Python coding standards? if x and x[0] > 0: pass =OR= if x: if x[0] > 0: pass In the first, I'm obviously making the

[Tutor] perplexing error with shelve

2007-10-30 Thread Orest Kozyar
I have a program which queries an online database (Medline) for XML data. It caches all data using shelve to avoid hitting the database too many times. For some reason, I keep getting a RuntimeError: maximum recursion depth exceeded when attempting to add a certain record. This program has succes

Re: [Tutor] perplexing error with shelve REVISED

2007-10-30 Thread Orest Kozyar
> Please post the entire traceback (omitting duplicate lines). Sorry, I should have included the traceback. I've revised the sample script so that it generates the traceback when run. The sample script is at the very bottom of this email. ### SCRIPT OUTPUT ### [kozyar]:~$ python exampl

Re: [Tutor] perplexing error with shelve REVISED

2007-10-31 Thread Orest Kozyar
This is on: Python 2.5 (r25:51908, Oct 19 2007, 09:46:41) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Redhat Fedora release 7 (Moonshine) x86 64 bit processor (SMP) > The program worked fine for me (python 2.5.1 - stackless on > Mac OSX). Can you provide details about your platform (pytho

Re: [Tutor] perplexing error with shelve REVISED

2007-10-31 Thread Orest Kozyar
the following error: 12 [main] python2.5 2700 _cygtls::handle_exceptions: Error while dumping state (probably corrupted stack) > -Original Message- > From: Orest Kozyar [mailto:[EMAIL PROTECTED] > Sent: Wednesday, October 31, 2007 4:27 PM > To: 'Aditya Lal' >

Re: [Tutor] perplexing error with shelve REVISED

2007-10-31 Thread Orest Kozyar
> It appears you have a cyclic reference in your doc object. > Try adding "doc.unlink()" before you add it to your shelf. That fixed the problem. I did not realize that XML documents could have cyclic references. Thanks for all your help! Orest ___

Re: [Tutor] perplexing error with shelve REVISED

2007-10-31 Thread Orest Kozyar
> It appears you have a cyclic reference in your doc object. > Try adding "doc.unlink()" before you add it to your shelf. Actually, I just realized that doc.unlink() seems to delete the entire XML content, which kind of defeats the purpose of caching it. I'll check on xml-sig and the comp.lang