Re: Enums and nested classes

2022-04-21 Thread Ethan Furman
On 4/21/22 15:00, Greg Ewing wrote: On 20/04/22 10:57 pm, Sam Ezeh wrote: Has anyone here used or attempted to use a nested class inside an enum? If so, how did you find it? (what did you expect to happen and did your expectations align with resulting behaviour etc.) That's a pretty open-ende

Re: Enums and nested classes

2022-04-21 Thread Greg Ewing
On 20/04/22 10:57 pm, Sam Ezeh wrote: Has anyone here used or attempted to use a nested class inside an enum? If so, how did you find it? (what did you expect to happen and did your expectations align with resulting behaviour etc.) That's a pretty open-ended question. Is there something about

Enums and nested classes

2022-04-20 Thread Sam Ezeh
Hello everyone, Has anyone here used or attempted to use a nested class inside an enum? If so, how did you find it? (what did you expect to happen and did your expectations align with resulting behaviour etc.) Here are two examples describing the situation I'm talking about ``` class Outer(Enum

Re: Enum with nested classes or with types as members

2018-09-12 Thread Ben Finney
Ethan Furman writes: > I'm asking because in doing some work on Enum it became apparent to me > that having nested classes was not a smooth, satisfying experience, > and I'm considering treating them the same way as methods (they will > no longer be converted into members

Enum with nested classes or with types as members

2018-09-11 Thread Ethan Furman
Greetings! So the stdlib Enum has been around for a few years now. Has anyone written an enum that either had types as members: class Types(Enum): Int = int Str = str or that had nested classes: class Types(Enum): class Contained(Enum): circle = 1

Re: Baroque [was Re: Should nested classes in an Enum be Enum members?]

2018-06-29 Thread Ethan Furman
On 06/29/2018 05:51 PM, Steven D'Aprano wrote: So not especially complimentary (sorry Ethan, but that was my first impression) but not *necessarily* a bad thing either. No worries! :) The Jargon File adjective that comes closest is probably gnarly: Wow, I haven't heard that word in a long

Re: Should nested classes in an Enum be Enum members?

2018-06-29 Thread Steven D'Aprano
On Fri, 29 Jun 2018 10:36:45 -0700, Ethan Furman wrote: >> What makes them enums? Under what circumstances would you be comparing >> something to MartinLutherKingJr (Day) without caring about a *specific* >> Martin Luther King Jr Day? > > Enums are also useful when the underlying value is relevan

Re: Baroque [was Re: Should nested classes in an Enum be Enum members?]

2018-06-29 Thread Chris Angelico
On Sat, Jun 30, 2018 at 10:51 AM, Steven D'Aprano wrote: > ["Baroque"] should not mean "weird or bizarre", although I've seen a couple of > lesser-quality dictionaries give that as a meaning. Which is itself weird > and bizarre :-) > I guess those dictionaries are baroque. Or maybe just broke. C

Baroque [was Re: Should nested classes in an Enum be Enum members?]

2018-06-29 Thread Steven D'Aprano
On Sat, 30 Jun 2018 09:02:37 +1000, Cameron Simpson wrote: > On 29Jun2018 10:36, Ethan Furman wrote: >>On 06/28/2018 10:52 PM, Steven D'Aprano wrote: >>>It isn't clear to me why FederalHoliday is an Enum, especially as the >>>API seems extremely baraque. >> >>Huh. I had to look that word up, an

Re: Should nested classes in an Enum be Enum members?

2018-06-29 Thread Gregory Ewing
Cameron Simpson wrote: It tends to mean "weird", but perhaps a more nuanced phrasing might be unusual and strange, and usually connotes some degree of over complication. When used in a derogatory way it means "excessively elaborate". The Baroque period was characterised by extremely ornate arch

Re: Should nested classes in an Enum be Enum members?

2018-06-29 Thread Gregory Ewing
Ethan Furman wrote: They are the list of dates in which US banks are closed for electronic business (funds transfers and things). That sems like something that would be better specified in a configuration file than hard-wired into the code, in case the rules change. -- Greg -- https://mail.pyt

Re: Should nested classes in an Enum be Enum members?

2018-06-29 Thread Jim Lee
On 06/29/18 16:02, Cameron Simpson wrote: On 29Jun2018 10:36, Ethan Furman wrote: On 06/28/2018 10:52 PM, Steven D'Aprano wrote: On Thu, 28 Jun 2018 18:33:31 -0700, Ethan Furman wrote: Perhaps I am using Enum incorrectly, but here is my FederalHoliday Enum.  Note that date(), next_business_

Re: Should nested classes in an Enum be Enum members?

2018-06-29 Thread Cameron Simpson
On 29Jun2018 10:36, Ethan Furman wrote: On 06/28/2018 10:52 PM, Steven D'Aprano wrote: On Thu, 28 Jun 2018 18:33:31 -0700, Ethan Furman wrote: Perhaps I am using Enum incorrectly, but here is my FederalHoliday Enum. Note that date(), next_business_day, and year() are all callables. The AutoE

Re: Should nested classes in an Enum be Enum members?

2018-06-29 Thread Ethan Furman
On 06/28/2018 10:52 PM, Steven D'Aprano wrote: On Thu, 28 Jun 2018 18:33:31 -0700, Ethan Furman wrote: Perhaps I am using Enum incorrectly, but here is my FederalHoliday Enum. Note that date(), next_business_day, and year() are all callables. The AutoEnum parent assigns values from 1 to n f

Re: Should nested classes in an Enum be Enum members?

2018-06-29 Thread Bart
On 29/06/2018 09:01, Ian Kelly wrote: On Thu, Jun 28, 2018 at 10:06 PM Ben Finney wrote: @total_ordering class ChessPiece(Enum): PAWN = 1, 'P' KNIGHT = 2, 'N' BISHOP = 3, 'B' ROOK = 4, 'R' # ... @property def label(self): return self.value[1]

Re: Should nested classes in an Enum be Enum members?

2018-06-29 Thread Ian Kelly
On Thu, Jun 28, 2018 at 10:06 PM Ben Finney wrote: > > Ethan Furman writes: > > > On 06/28/2018 05:58 PM, Ben Finney wrote: > > > > > So I remain dumbfounded as to why anyone would want a class to *both* be > > > an enumerated type, *and* have callable attributes in its API. > > > > Perhaps I am

Re: Should nested classes in an Enum be Enum members?

2018-06-29 Thread Ian Kelly
On Thu, Jun 28, 2018 at 7:01 PM Ben Finney wrote: > > Ian Kelly writes: > > > On Thu, Jun 28, 2018 at 4:38 AM Ben Finney > > wrote: > > > > > > Ethan Furman writes: > > > > > > Specifically, I can't make sense of why someone would want to have a > > > class that is simultaneously behaving as a

Re: Should nested classes in an Enum be Enum members?

2018-06-28 Thread Steven D'Aprano
On Thu, 28 Jun 2018 18:33:31 -0700, Ethan Furman wrote: > On 06/28/2018 05:58 PM, Ben Finney wrote: > >> So I remain dumbfounded as to why anyone would want a class to *both* >> be an enumerated type, *and* have callable attributes in its API. > > Perhaps I am using Enum incorrectly, but here is

Re: Should nested classes in an Enum be Enum members?

2018-06-28 Thread Ben Finney
Ethan Furman writes: > On 06/28/2018 05:58 PM, Ben Finney wrote: > > > So I remain dumbfounded as to why anyone would want a class to *both* be > > an enumerated type, *and* have callable attributes in its API. > > Perhaps I am using Enum incorrectly, but here is my FederalHoliday > Enum. […] Th

Re: Should nested classes in an Enum be Enum members?

2018-06-28 Thread Ethan Furman
On 06/28/2018 05:58 PM, Ben Finney wrote: So I remain dumbfounded as to why anyone would want a class to *both* be an enumerated type, *and* have callable attributes in its API. Perhaps I am using Enum incorrectly, but here is my FederalHoliday Enum. Note that date(), next_business_day, and

Re: Should nested classes in an Enum be Enum members?

2018-06-28 Thread Steven D'Aprano
On Thu, 28 Jun 2018 20:34:58 +1000, Ben Finney wrote: > Ethan Furman writes: > >> Consider the following Enum definition: >> >> class Color(Enum): >> RED = 1 >> GREEN = 2 >> BLUE = 3 >> @property >> def lower(self): >> return self.name.lower() >> d

Re: Should nested classes in an Enum be Enum members?

2018-06-28 Thread Steven D'Aprano
On Thu, 28 Jun 2018 08:36:47 -0700, Ethan Furman wrote: >>> Answer: >>> >>> - RED, GREEN, and BLUE are members >>> - lower and spam() are not >>> - SomeClass /is/ a member (but not its instances) >> >> Is that by accident or by design? > > By design. It is entirely possible to want a

Re: Should nested classes in an Enum be Enum members?

2018-06-28 Thread Ben Finney
Ian Kelly writes: > On Thu, Jun 28, 2018 at 4:38 AM Ben Finney wrote: > > > > Ethan Furman writes: > > > > Specifically, I can't make sense of why someone would want to have a > > class that is simultaneously behaving as an enumerated type, *and* > > has an API of custom callable attributes. >

Re: Should nested classes in an Enum be Enum members?

2018-06-28 Thread Ian Kelly
On Thu, Jun 28, 2018 at 4:38 AM Ben Finney wrote: > > Ethan Furman writes: > > > Consider the following Enum definition: > > > > class Color(Enum): > > RED = 1 > > GREEN = 2 > > BLUE = 3 > > @property > > def lower(self): > > return self.name.lower() > >

Re: Should nested classes in an Enum be Enum members?

2018-06-28 Thread Ethan Furman
is really seems to be the sticking point -- what should an Enum of Enums look like? For example, should the above do --> list(Colour) [Colour.PrimaryColour <...>, Colour.SecondaryColour <...>] or something else? The only example I have seen so far of nested classes in an Enum is

Re: Should nested classes in an Enum be Enum members?

2018-06-28 Thread Ben Finney
Ethan Furman writes: > Consider the following Enum definition: > > class Color(Enum): > RED = 1 > GREEN = 2 > BLUE = 3 > @property > def lower(self): > return self.name.lower() > def spam(self): > return "I like %s eggs and spam!" % self.l

Re: Should nested classes in an Enum be Enum members?

2018-06-28 Thread Steven D'Aprano
erit from Enum: class Colour(Enum): class PrimaryColour(Enum): RED = 1 GREEN = 2 BLUE = 3 OCTARINE = 8 class SecondaryColour(Enum): PUCE = 101 MAUVE = 102 BEIGE = 103 TEAL = 104 > The only example I have seen so far of nested clas

Should nested classes in an Enum be Enum members?

2018-06-27 Thread Ethan Furman
t its instances) Question: Should `SomeClass` be an enum member? When would it be useful to have an embedded class in an Enum be an enum member? The only example I have seen so far of nested classes in an Enum is when folks want to make an Enum of Enums, and the nested Enum should not it

Re: Python C-API: how to define nested classes?

2013-05-16 Thread Stefan Behnel
Serge WEINSTOCK, 16.05.2013 10:55: > I'm currently writing a C extension module for python using the "raw" C-API. > I would like to be able to define "nested classes" like in the following > python code > > =

Re: Python C-API: how to define nested classes?

2013-05-16 Thread 88888 Dihedral
Serge WEINSTOCK於 2013年5月16日星期四UTC+8下午4時55分07秒寫道: > Hi, > >   > > I'm currently writing a C extension module for python using the "raw" C-API. > I would like to be able to define "nested classes

Python C-API: how to define nested classes?

2013-05-16 Thread Serge WEINSTOCK
Hi, I'm currently writing a C extension module for python using the "raw" C-API. I would like to be able to define "nested classes" like in the following python code class A: class B:

Re: how to create nested classes dynamically

2009-11-03 Thread Gabriel Genellina
class attributes because the statements bb=... and cc=... are inside the class definition). It works, but perhaps that's not what you want. If you want instance attributes instead, create them in AA.__init__ by using self.bb=something Nested classes provide no benefit here an

how to create nested classes dynamically

2009-11-03 Thread gopal mishra
I have class structure as below. How can I create the following nested class and its properties dynamically. class AA(object): class BB(object): def setBB1(self, value): ##some code def getBB1(self): bb1 = #somecode return bb1

Re: Nested Classes and Instances

2009-07-10 Thread J. Cliff Dyer
On Fri, 2009-07-10 at 19:00 +0200, Manuel Graune wrote: > Hello, > > as an example of what I would like to achieve, think of a street > where each house has a door and a sign with a unique (per house) > number on it. I tried to model this like this: > > class House(object): > class Door(objec

Re: Nested Classes and Instances

2009-07-10 Thread Peter Otten
Manuel Graune wrote: > as an example of what I would like to achieve, think of a street > where each house has a door and a sign with a unique (per house) > number on it. I tried to model this like this: > > class House(object): > class Door(object): > def __init__(self,color): >

Nested Classes and Instances

2009-07-10 Thread Manuel Graune
Hello, as an example of what I would like to achieve, think of a street where each house has a door and a sign with a unique (per house) number on it. I tried to model this like this: class House(object): class Door(object): def __init__(self,color): self.color=color

Re: nested classes

2009-03-20 Thread Esmail
> Yes. It's the same convention used to indicate that a method is > "private" in Python, since the language itself has no privacy > mechanisms. Great - got it! Thanks again, Esmail -- http://mail.python.org/mailman/listinfo/python-list

Re: nested classes

2009-03-20 Thread Chris Rebert
On Fri, Mar 20, 2009 at 1:24 PM, Esmail wrote: > On Mar 20, 2:41 pm, Chris Rebert wrote: >> 2009/3/20 Benjamin Kaplan : >> > On Fri, Mar 20, 2009 at 10:06 AM, Esmail wrote: >> >> >> Hello all, >> >> >> I am curious why nested classes don&#

Re: nested classes

2009-03-20 Thread Esmail
On Mar 20, 2:35 pm, Steve Holden wrote: > Benjamin Kaplan wrote: > > > On Fri, Mar 20, 2009 at 10:06 AM, Esmail > <mailto:ebo...@gmail.com>> wrote: > > >     Hello all, > > >     I am curious why nested classes don't seem to be used much

Re: nested classes

2009-03-20 Thread Esmail
On Mar 20, 2:41 pm, Chris Rebert wrote: > 2009/3/20 Benjamin Kaplan : > > > > > > > On Fri, Mar 20, 2009 at 10:06 AM, Esmail wrote: > > >> Hello all, > > >> I am curious why nested classes don't seem to be used much in Python. > >>

Re: nested classes

2009-03-20 Thread Chris Rebert
2009/3/20 Benjamin Kaplan : > > > On Fri, Mar 20, 2009 at 10:06 AM, Esmail wrote: >> >> Hello all, >> >> I am curious why nested classes don't seem to be used much in Python. >> I see them as a great way to encapsulate related information, which i

Re: nested classes

2009-03-20 Thread Steve Holden
Benjamin Kaplan wrote: > > > On Fri, Mar 20, 2009 at 10:06 AM, Esmail <mailto:ebo...@gmail.com>> wrote: > > Hello all, > > I am curious why nested classes don't seem to be used much in Python. > I see them as a great way to encapsulate

Re: nested classes

2009-03-20 Thread Benjamin Kaplan
On Fri, Mar 20, 2009 at 10:06 AM, Esmail wrote: > Hello all, > > I am curious why nested classes don't seem to be used much in Python. > I see them as a great way to encapsulate related information, which is > a > good thing. > > In my other post "improve th

nested classes

2009-03-20 Thread Esmail
Hello all, I am curious why nested classes don't seem to be used much in Python. I see them as a great way to encapsulate related information, which is a good thing. In my other post "improve this newbie code/nested functions in Python?" (I accidentally referred to nested function

Re: Inheritance in nested classes

2005-11-15 Thread gmilas
"I'm using the Active Server Pages integration in the win32 extensions, does anyone have good/bad experiences using this interface?" What is it you are trying to do? I'm using python2.4 with win32 and IIS/python ASP and find it ok. There were at some point some session overlappings but I'm not su

Re: Inheritance in nested classes

2005-11-15 Thread George Sakkis
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > But I hope you are aware that nested classes aren't quite the same as > they are in java, are you? Actually they are more like java's static inner classes. If you want to simulate non-static inner classes in pytho

Re: Inheritance in nested classes

2005-11-15 Thread Diez B. Roggisch
Martin Skou wrote: > I'm experimenting with using Python for a small web interface, using > Mark Hammond's nice win32 extensions. > > I use a small class hierarchy which uses inheritance and nested classes. > > Here are a small extract of the code: > > class p

Inheritance in nested classes

2005-11-15 Thread Martin Skou
I'm experimenting with using Python for a small web interface, using Mark Hammond's nice win32 extensions. I use a small class hierarchy which uses inheritance and nested classes. Here are a small extract of the code: class page: def __init__(self):

Re: Newby Q: nested classes, access of upper method

2004-12-04 Thread Gregor Horvath
Hello Nick, thank you, your answer really helped me.. -- Greg Nick Coghlan wrote: Gregor Horvath wrote: Hello, class A(self): def A1(): pass class B(self): def B1(): # #*** How can I access A1 here *** #***

Re: Newby Q: nested classes, access of upper method

2004-12-04 Thread Nick Coghlan
Gregor Horvath wrote: Hello, class A(self): def A1(): pass class B(self): def B1(): # #*** How can I access A1 here *** # self.A1() # doesnet work because self references to B self.

Newby Q: nested classes, access of upper method

2004-12-03 Thread Gregor Horvath
Hello, class A(self): def A1(): pass class B(self): def B1(): # #*** How can I access A1 here *** # self.A1() # doesnet work because self references to B self.self.A