Re: [Python-ideas] possible attribute-oriented class

2009-09-08 Thread Jim Jewett
On Mon, Sep 7, 2009 at 9:02 PM, Jan Kaliszewski wrote: > 08-09-2009 o 02:15:10 Steven D'Aprano wrote: >> ... what's wrong with this? > a['xyz'] = something['blablabla'] + somethingelse['foobar'] > b['ababababa'] += afun(bobo['dodo']['kookoo'] * pofopofo['gh'][0]['a']) > cupu['abc'] = (kukumunu['

Re: possible attribute-oriented class

2009-09-07 Thread Ken Newton
On Mon, Sep 7, 2009 at 6:02 PM, Jan Kaliszewski wrote: ... > > I think it depends how often people need to implement such boiler-plate > code for themselves. Now I see that this thread is not very popular, so > indeed maybe you are right... Though it'd be nice to have OOTB such > a factory in `coll

Re: possible attribute-oriented class

2009-09-07 Thread Jan Kaliszewski
08-09-2009 o 02:15:10 Steven D'Aprano wrote: On Mon, 7 Sep 2009 09:37:35 am Jan Kaliszewski wrote: 06-09-2009 o 20:20:21 Ethan Furman wrote: > ... I love being able to type > >current_record.full_name == last_record.full_name > > instead of > >current_record['full_name'] == last_re

Re: possible attribute-oriented class

2009-09-06 Thread Jan Kaliszewski
06-09-2009 o 20:20:21 Ethan Furman wrote: In the dbf module I wrote, I use both the attribute access and the key lookup. The attribute access is great for interactive use, and for all the routines that play with the tables we have at work, where all the field names are indeed known at com

Re: possible attribute-oriented class

2009-09-06 Thread Ethan Furman
Steven D'Aprano wrote: On Fri, 04 Sep 2009 22:51:39 -0700, Ken Newton wrote: I would think this is much more than just copy from other language styles or 'just' a syntax change -- the apparent widespread use would hint at a deeper need. "Apparent" is the key word there. There are lots of peo

Re: possible attribute-oriented class

2009-09-05 Thread Jan Kaliszewski
05-09-2009 Steven D'Aprano wrote: On Fri, 04 Sep 2009 22:37:15 +0200, Jan Kaliszewski wrote: Named tuples (which indeed are really very nice) are read-only, but the approach they represent could (and IMHO should) be extended to some kind of mutable objects. [snip] What sort of extensions di

Re: possible attribute-oriented class

2009-09-05 Thread Steven D'Aprano
On Fri, 04 Sep 2009 22:51:39 -0700, Ken Newton wrote: > On Fri, Sep 4, 2009 at 9:49 PM, Steven > D'Aprano wrote: ... >> >>> The old discussion, the above link points to, shows that such a >>> dot-accessible dict-like class is something that many people need and >>> repeatedly implemet it (more or

Re: possible attribute-oriented class

2009-09-04 Thread Ken Newton
On Fri, Sep 4, 2009 at 9:49 PM, Steven D'Aprano wrote: ... > >> The old discussion, the above link points to, shows that such a >> dot-accessible dict-like class is something that many people need and >> repeatedly implemet it (more or less perfectly) for themselves. > > I think it's something whic

Re: possible attribute-oriented class

2009-09-04 Thread Steven D'Aprano
On Fri, 04 Sep 2009 22:37:15 +0200, Jan Kaliszewski wrote: > Named tuples (which indeed are really very nice) are read-only, but the > approach they represent could (and IMHO should) be extended to some kind > of mutable objects. What do you mean "read-only"? Do you mean immutable? What sort of

Re: [Python-ideas] possible attribute-oriented class

2009-09-04 Thread George Sakkis
On Fri, Sep 4, 2009 at 4:37 PM, Jan Kaliszewski wrote: > 04-09-2009 Ken Newton wrote: > >> I like this version very much. I'm ready to put this into practice to see >> how it works in practice. > > [snip] > > Not only you (Ken) and me. :-) It appears that the idea is quite old. Nick > Coghlan repl

Re: possible attribute-oriented class

2009-09-04 Thread Jan Kaliszewski
04-09-2009 Ken Newton wrote: I like this version very much. I'm ready to put this into practice to see how it works in practice. [snip] Not only you (Ken) and me. :-) It appears that the idea is quite old. Nick Coghlan replied at python-id...@python.org: Jan Kaliszewski wrote: What do you

Re: possible attribute-oriented class

2009-09-04 Thread Ken Newton
I like this version very much. I'm ready to put this into practice to see how it works in practice. A minor point: I envision this to be used in a context where all key values are strings (legal attribute identifiers). But constructing an AttrClass from a dict or setting values directly with the

Re: possible attribute-oriented class

2009-09-04 Thread Scott David Daniels
Ken Newton wrote: ... I would appreciate comments on this code. First, is something like this already done? Second, are there reasons for not doing this? ... class AttrClass(object): ... def __repr__(self): return "%s(%s)" % (self.__class__.__name__, self.__dict__.__repr__()

Re: possible attribute-oriented class

2009-09-04 Thread Colin J. Williams
Jan Kaliszewski wrote: [originally from python-list@python.org, crossposted to python-id...@python.org] 04-09-2009 o 00:46:01 Ken Newton wrote: I have created the following class definition with the idea of making a clean syntax for non-programmers to created structured data within a python

Re: possible attribute-oriented class

2009-09-04 Thread Jan Kaliszewski
[originally from python-list@python.org, crossposted to python-id...@python.org] 04-09-2009 o 00:46:01 Ken Newton wrote: I have created the following class definition with the idea of making a clean syntax for non-programmers to created structured data within a python environment. I would ap

Re: possible attribute-oriented class

2009-09-04 Thread Peter Otten
Ken Newton wrote: > class AttrClass(object): > """AttrClass lets you freely add attributes in nested manner""" > > def __init__(self): > pass > def __setitem__(self, key, value): > return self.__dict__.__setitem__(key, value) > def __repr__(self): > return

Re: possible attribute-oriented class

2009-09-03 Thread Ken Newton
On Thu, Sep 3, 2009 at 4:30 PM, Steven D'Aprano < st...@remove-this-cybersource.com.au> wrote: > On Thu, 03 Sep 2009 15:46:01 -0700, Ken Newton wrote: > > > I have created the following class definition with the idea of making a > > clean syntax for non-programmers to created structured data withi

Re: possible attribute-oriented class

2009-09-03 Thread Steven D'Aprano
On Thu, 03 Sep 2009 15:46:01 -0700, Ken Newton wrote: > I have created the following class definition with the idea of making a > clean syntax for non-programmers to created structured data within a > python environment. What do you expect non-programmers to do with this class, without programmi

possible attribute-oriented class

2009-09-03 Thread Ken Newton
I have created the following class definition with the idea of making a clean syntax for non-programmers to created structured data within a python environment. I would appreciate comments on this code. First, is something like this already done? Second, are there reasons for not doing this? If t