Re: What do you use as symbols for Python ?

2005-11-12 Thread Chris Smith
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

Re: What do you use as symbols for Python ?

2005-11-12 Thread Daniel Evers
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

Re: What do you use as symbols for Python ?

2005-11-11 Thread Sion Arrowsmith
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

Re: What do you use as symbols for Python ?

2005-11-11 Thread Scott David Daniels
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

Re: What do you use as symbols for Python ?

2005-11-11 Thread Daniel Evers
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

Re: What do you use as symbols for Python ?

2005-11-11 Thread gsteff
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

Re: What do you use as symbols for Python?

2005-11-11 Thread Björn Lindström
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,

Re: What do you use as symbols for Python ?

2005-11-11 Thread Peter Otten
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

Re: What do you use as symbols for Python ?

2005-11-10 Thread George Sakkis
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,

Re: What do you use as symbols for Python ?

2005-11-10 Thread bruno at modulix
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

Re: What do you use as symbols for Python ?

2005-11-10 Thread Antoon Pardon
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

Re: What do you use as symbols for Python ?

2005-11-10 Thread Gary Herron
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

Re: What do you use as symbols for Python ?

2005-11-10 Thread Pierre Barbier de Reuille
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

Re: What do you use as symbols for Python ?

2005-11-10 Thread Scott David Daniels
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

Re: What do you use as symbols for Python ?

2005-11-10 Thread Lonnie Princehouse
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',

Re: What do you use as symbols for Python ?

2005-11-09 Thread Erik Max Francis
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