Gary == Gary Herron [EMAIL PROTECTED] writes:
Gary Erik Max Francis wrote:
Pierre Barbier de Reuille wrote:
When you need some symbols in your program, what do you use in
Python ?
For example, an object get a state. This state is more
readable if expressed as a
Peter Otten wrote:
You should ditch what follows and instead add just
def __iter__(self):
return iter(self.__keys)
Mhh. I should start learning the builtins ... :)
To see the problem with your original code (an object serving as its own
iterator) try the
Gary Herron [EMAIL PROTECTED] wrote:
Another similar approach that keeps those values together in a single
namespace is this (my favorite):
class State:
OPENED, CLOSED, ERROR = range(3)
Then you can refer to the values as
State.OPENED
State.CLOSED
State.ERROR
The extra
Sion Arrowsmith wrote:
...
class State:
Enum = range(3)
OPENED, CLOSED, ERROR = Enum
Names = { OPENED: OPENED, CLOSED: CLOSED, ERROR: ERROR }
so you can used State.Names[state] to provide something user-readable, ...
Or use a function like:
def named(value, classes):
for
Hi!
Never would have thought of this...
I mixed this with the class-version and created a new class derived from
str for easier printing and added an iterator:
---
class Enum:
class Type(str):
def __init__(self, name):
self.__name = name
I've seen the following style in some code (the formencode library
comes to mind):
opened = object()
closed = object()
error = object()
Greg
--
http://mail.python.org/mailman/listinfo/python-list
Gary Herron [EMAIL PROTECTED] writes:
Another similar approach that keeps those values together in a single
namespace is this (my favorite):
class State:
OPENED, CLOSED, ERROR = range(3)
Then you can refer to the values as
State.OPENED
State.CLOSED
State.ERROR
Of course,
Daniel Evers wrote:
I mixed this with the class-version and created a new class derived from
str for easier printing and added an iterator:
---
class Enum:
class Type(str):
def __init__(self, name):
self.__name = name
def
Erik Max Francis [EMAIL PROTECTED] wrote:
Pierre Barbier de Reuille wrote:
When you need some symbols in your program, what do you use in Python ?
For example, an object get a state. This state is more readable if
expressed as a symbols, for example opened, closed, error.
Typically,
Pierre Barbier de Reuille wrote:
When you need some symbols in your program, what do you use in Python ?
For example, an object get a state. This state is more readable if
expressed as a symbols, for example opened, closed, error.
Typically, in C or C++, I would use an enum for that:
enum
Op 2005-11-10, Pierre Barbier de Reuille schreef [EMAIL PROTECTED]:
When you need some symbols in your program, what do you use in Python ?
For example, an object get a state. This state is more readable if
expressed as a symbols, for example opened, closed, error.
Typically, in C or C++, I
Erik Max Francis wrote:
Pierre Barbier de Reuille wrote:
When you need some symbols in your program, what do you use in Python ?
For example, an object get a state. This state is more readable if
expressed as a symbols, for example opened, closed, error.
Typically, in C or C++, I would use
Well, thank you all !
I still feel it could be good for Python to have some kind of symbols
built in, and I will try to expose that to the python-dev list, to see
their reaction.
But in the different solutions proposed, the one I prefer is probably
the definitions of contants in a class to group
Pierre Barbier de Reuille wrote:
Well, thank you all !
I still feel it could be good for Python to have some kind of symbols
built in, and I will try to expose that to the python-dev list, to see
their reaction.
But in the different solutions proposed, the one I prefer is probably
the
I use custom classes and the is operator... that way, things don't
get confused with integers, and I have an object where repr(state) will
give me more than an integer. (the integer approach works well enough
but seems like a case of I can program C in ANY language!)
opened = type('opened',
Pierre Barbier de Reuille wrote:
When you need some symbols in your program, what do you use in Python ?
For example, an object get a state. This state is more readable if
expressed as a symbols, for example opened, closed, error.
Typically, in C or C++, I would use an enum for that:
enum
16 matches
Mail list logo