Re: Expandable 2D Dictionaries?

2007-07-08 Thread genro
On Jul 6, 5:43 pm, Robert Dailey <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am interested in creating an expandable (dynamic) 2D dictionary. For
> example:
>
> myvar["cat"]["paw"] = "Some String"
>
> The above example assumes "myvar" is declared. In order for this to
> work, I have to know ahead of time the contents of the dictionary. For
> the above to work, my declaration must look like:
>
> myvar = {"cat": {"paw":""} }
>
> I would like to not have to declare my dictionary like this, as it
> does not allow it to be expandable. I'm very new to Python (I'm a
> professional C++ programmer. Any comparisons to C++ would help me
> understand concepts).
>
> Is there a way that when I index into my dictionary using an "unknown"
> index (string), that python will dynamically add that key/value pair?
>
> Thanks.

Hi Robert
take a look to our Bag module ( http://trac.genropy.org/wiki/BagManual).
Bag is a hierarchical container that can be used as nested dictionary.
If you are interested I'll send you the module.
There is not yet a public DL link as documentation has still to be
tuned...

HTH

Giovanni

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way for missing dict keys

2007-07-21 Thread genro
On Jul 19, 6:29 am, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:

>
> Myobject will be instanciated each time, yes.
>
> > and so if the initialization is expensive you
> > will probably see surprises.
>
> No "surprise" here, but it can indeed be suboptimal if instanciating
> myobject is costly.

What about this way ?

my_obj = my_dict.get(key) or my_dict.setdefault(key,myobject())

Ciao
G.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie: self.member syntax seems /really/ annoying

2007-09-12 Thread genro
On Sep 12, 6:21 am, Charles Fox <[EMAIL PROTECTED]> wrote:
> I've just started playing around with Python, as a possible
> replacement for a mix of C++, Matlab and Lisp.  The language looks
> lovely and clean with one huge exception:  I do a lot of numerical
> modeling, so I deal with objects (like neurons) described
> mathematically in papers, by equations like
> a_dot = -k(a-u)
> In other languages, this translates nicely into code, but as far as I
> can tell, Python needs the ugly:
> self.a_dot = -self.k(self.a-self.u)
> For large equations this is going to make my code seriously unreadable
> to the point of needing to switch back to Matlab -- and it seems to go
> against everything else about python's simplicity and elegance.  Am I
> missing something?  Is there something like a 'with' command that lets
> me set the scope, like
>
> with self:
>   .a_dot = -.k(.a-.u)
>
> It's premature to make language suggestions as I am new to the
> language, but I would have though that making a 'with self' explicit
> in all methods would have been neat, so I could just write
>   .a_dot = -.k(.a-.u)
> which would still avoid confusion with local function variables, since
> '.a' is different from 'a'.
>
> Please help if I am missing something -- this looks like a great
> language but I am going to mad trying to read numerical code full of
> 'self.'s breaking up the equations.

Just an idea: I think that if you have to get a more readable code
you
could abstract the function from the object using a significative
name and then use this named function passing **self.__dict__

For example in your module you could write:

#-- functional section ---


def dothis(k,a,u):
return k*(a-u)

def dothat(m,r,k):
return m*r+(k.m)^m


#- Class definition --

class Bar(object):

def foo(self):
self.a_dot = dothis(**self.__dict__)
self.boo = dothat(**self.__dict__)

In this way the functional part is pure expression and very readable.


HTH

G.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another comparison of Python Web Frameworks

2007-10-07 Thread genro
On Oct 7, 8:35 am, Michele Simionato <[EMAIL PROTECTED]>
wrote:
> On Oct 6, 12:57 pm, Bruno Desthuilliers
>
> > Michele Simionato a écrit :
>
> > > I looked at the source code and it seems fine to me, but I have
> > > not used it directly, not stressed it. I need a
> > > production-level WSGI session middleware and I wonder what the
> > > players are (for instance how Beaker does compare with flup?)
>
> > Can't tell, but I'd trust the Pylons team on this kind of choices.
> > They're doing good job so far AFAICT.
>
> Probably Beaker works well, but it is certainly NOT doing things
> as Eby recommends:
>
> http://dirtsimple.org/2007/02/wsgi-middleware-considered-harmful.html
>
> BTW, I know that Eby is asking opinions about WSGI 2.0 on the
> WSGI SIG and interested people may have a look there.
>
>Michele Simionato


I think that Beaker is a Mako dependency.
So if you use Mako, Beaker is not an option  :)

G

-- 
http://mail.python.org/mailman/listinfo/python-list