Re: class declaration shortcut

2007-03-02 Thread Bjoern Schliessmann
Steven D'Aprano wrote: Overkill? Storage of a single attribute holding a (usually short) string is overkill? No, but storing the first name a class is bound to in it is a bit of, IMHO. When you do that, you wouldn't expect the __name__ of some.module.function to change to f, and it

Re: class declaration shortcut

2007-03-02 Thread Arnaud Delobelle
On Mar 2, 3:01 pm, Bjoern Schliessmann usenet- [EMAIL PROTECTED] wrote: Steven D'Aprano wrote: Overkill? Storage of a single attribute holding a (usually short) string is overkill? No, but storing the first name a class is bound to in it is a bit of, IMHO. Don't see it as the first name a

Re: class declaration shortcut

2007-03-02 Thread Bjoern Schliessmann
Arnaud Delobelle wrote: Don't see it as the first name a class is bound to, but rather as the name a class is defined as. If class_object.__name__ == 'Foo' it means that somewhere in your code there is a class definition: class Foo: # stuff Same for function: if

Re: class declaration shortcut

2007-03-02 Thread Arnaud Delobelle
On Mar 2, 8:28 pm, Bjoern Schliessmann usenet- [EMAIL PROTECTED] wrote: This is somehow contrary to my understanding of the Python names concept. What if I use a loop to define several classes based on data -- they'll all have the same __name__ unless I change it manually. Well that's not a

Re: class declaration shortcut

2007-03-02 Thread MonkeeSage
On Feb 28, 1:26 pm, Luis M. González [EMAIL PROTECTED] wrote: I've come across a code snippet in www.rubyclr.com where they show how easy it is to declare a class compared to equivalent code in c#. I wonder if there is any way to emulate this in Python. I posted like 10 minutes ago, but it

Re: class declaration shortcut

2007-03-02 Thread Luis M. González
On Mar 2, 8:29 pm, MonkeeSage [EMAIL PROTECTED] wrote: On Feb 28, 1:26 pm, Luis M. González [EMAIL PROTECTED] wrote: I've come across a code snippet inwww.rubyclr.comwhere they show how easy it is to declare a class compared to equivalent code in c#. I wonder if there is any way to emulate

Re: class declaration shortcut

2007-03-02 Thread MonkeeSage
On Mar 2, 5:48 pm, Luis M. González [EMAIL PROTECTED] wrote: Thanks for your detailed reply! So after all, the www.rubyclr.com code is not a fair comparison. Because the c# code shows a class definition, and the ruby code shows a struct definition, which is not equivalent to a class. Is that

Re: class declaration shortcut

2007-03-01 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Bjoern Schliessmann wrote: Bruno Desthuilliers wrote: class Toto(object): pass print Toto.__name__ Okay, I revoke my statement and assert the opposite. But what's it (__name__) good for? As objects don't know to which name they are bound, that's a good

Re: class declaration shortcut

2007-03-01 Thread Michele Simionato
On Mar 1, 9:40 am, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: In [EMAIL PROTECTED], Bjoern Schliessmann wrote: But what's it (__name__) good for? As objects don't know to which name they are bound, that's a good way to give some information in stack traces or when doing

Re: class declaration shortcut

2007-03-01 Thread Bjoern Schliessmann
Michele Simionato wrote: On Mar 1, 9:40 am, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] In [EMAIL PROTECTED], Bjoern Schliessmann But what's it (__name__) good for? As objects don't know to which name they are bound, that's a good way to give some information in stack traces or when doing

Re: class declaration shortcut

2007-03-01 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Bjoern Schliessmann wrote: Michele Simionato wrote: On Mar 1, 9:40 am, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] In [EMAIL PROTECTED], Bjoern Schliessmann But what's it (__name__) good for? As objects don't know to which name they are bound, that's a good way to

Re: class declaration shortcut

2007-03-01 Thread BJörn Lindqvist
On 28 Feb 2007 13:53:37 -0800, Luis M. González [EMAIL PROTECTED] wrote: Hmmm... not really. The code above is supposed to be a shorter way of writing this: class Person: def __init__(self, name, birthday, children): self.name = name self.birthday = birthday

Re: class declaration shortcut

2007-03-01 Thread Arnaud Delobelle
On Feb 28, 7:26 pm, Luis M. González [EMAIL PROTECTED] wrote: I've come across a code snippet inwww.rubyclr.comwhere they show how easy it is to declare a class compared to equivalent code in c#. I wonder if there is any way to emulate this in Python. The code is as follows: Person =

Re: class declaration shortcut

2007-03-01 Thread Steven Bethard
Arnaud Delobelle wrote: On Feb 28, 7:26 pm, Luis M. González [EMAIL PROTECTED] wrote: I've come across a code snippet inwww.rubyclr.comwhere they show how easy it is to declare a class compared to equivalent code in c#. I wonder if there is any way to emulate this in Python. The code is as

Re: class declaration shortcut

2007-03-01 Thread Arnaud Delobelle
On Mar 1, 4:01 pm, Steven Bethard [EMAIL PROTECTED] wrote: Arnaud Delobelle wrote: [...] This does pretty much the same thing as the recipe I posted: Not at all. My new_struct create returns a new class which is similar to a C struct (notice the __slots__). The recipe you refer to is nothing

Re: class declaration shortcut

2007-03-01 Thread Steven Bethard
Arnaud Delobelle wrote: On Mar 1, 4:01 pm, Steven Bethard [EMAIL PROTECTED] wrote: Arnaud Delobelle wrote: [...] This does pretty much the same thing as the recipe I posted: Not at all. My new_struct create returns a new class which is similar to a C struct (notice the __slots__). The

Re: class declaration shortcut

2007-03-01 Thread Arnaud Delobelle
On Mar 1, 7:37 pm, Steven Bethard [EMAIL PROTECTED] wrote: Arnaud Delobelle wrote: On Mar 1, 4:01 pm, Steven Bethard [EMAIL PROTECTED] wrote: Arnaud Delobelle wrote: [...] This does pretty much the same thing as the recipe I posted: Not at all. My new_struct create returns a new class

Re: class declaration shortcut

2007-03-01 Thread Steven Bethard
Arnaud Delobelle wrote: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/502237 [snip] Although I don't see the necessity of a metaclass: you could have class Record(object): def __init__(self, *vals): for slot, val in zip(self.__slots__, vals):

Re: class declaration shortcut

2007-03-01 Thread Luis M. González
On Mar 1, 3:03 pm, Arnaud Delobelle [EMAIL PROTECTED] wrote: On Mar 1, 4:01 pm, Steven Bethard [EMAIL PROTECTED] wrote: Arnaud Delobelle wrote: [...] This does pretty much the same thing as the recipe I posted: Not at all. My new_struct create returns a new class which is similar to a C

Re: class declaration shortcut

2007-03-01 Thread Steven Bethard
Luis M. González wrote: This is the closest we got so far to the intended result. If there was a way to enter attributes without quotes, it would be almost identical. Ok, below is the Python code so that the following works:: class Person(Struct): name birthday children Note that * The

Re: class declaration shortcut

2007-03-01 Thread Steven D'Aprano
On Thu, 01 Mar 2007 10:44:48 +0100, Bjoern Schliessmann wrote: Mh. I suspect there's also more to it than I see now, but this __name__ seems quite useless to me. What if I rebind the class' name after definition? Or is it really just for some manual introspection? If it is, it seems a bit of

Re: class declaration shortcut

2007-02-28 Thread Bruno Desthuilliers
Luis M. González a écrit : I've come across a code snippet in www.rubyclr.com where they show how easy it is to declare a class compared to equivalent code in c#. I wonder if there is any way to emulate this in Python. The code is as follows: Person = struct.new( :name, :birthday,

Re: class declaration shortcut

2007-02-28 Thread Steven Bethard
Luis M. González wrote: I've come across a code snippet in www.rubyclr.com where they show how easy it is to declare a class compared to equivalent code in c#. I wonder if there is any way to emulate this in Python. The code is as follows: Person = struct.new( :name, :birthday, :children)

Re: class declaration shortcut

2007-02-28 Thread Luis M. González
On Feb 28, 6:21 pm, Steven Bethard [EMAIL PROTECTED] wrote: Luis M. González wrote: I've come across a code snippet inwww.rubyclr.comwhere they show how easy it is to declare a class compared to equivalent code in c#. I wonder if there is any way to emulate this in Python. The code is as

Re: class declaration shortcut

2007-02-28 Thread Steven Bethard
Luis M. González wrote: On Feb 28, 6:21 pm, Steven Bethard [EMAIL PROTECTED] wrote: How about something like:: class Person(Record): __slots__ = 'name', 'birthday', 'children' You can then use the class like:: person = Person('Steve', 'April 25', []) assert

Re: class declaration shortcut

2007-02-28 Thread Bjoern Schliessmann
Luis M. González wrote: I've come across a code snippet in www.rubyclr.com where they show how easy it is to declare a class compared to equivalent code in c#. I wonder if there is any way to emulate this in Python. The code is as follows: Person = struct.new( :name, :birthday,

Re: class declaration shortcut

2007-02-28 Thread Bruno Desthuilliers
Bjoern Schliessmann a écrit : (snip) In Python, classes have no name. class Toto(object): pass print Toto.__name__ -- http://mail.python.org/mailman/listinfo/python-list

Re: class declaration shortcut

2007-02-28 Thread Bjoern Schliessmann
Bruno Desthuilliers wrote: class Toto(object): pass print Toto.__name__ Okay, I revoke my statement and assert the opposite. But what's it (__name__) good for? Regards, Björn -- BOFH excuse #179: multicasts on broken packets --