Paul McGuire wrote:
> class Constants(object):
> pass
>
> Then I defined the context for my LEFT and RIGHT constants, which are being
> created to specify operator associativity, and then my constant fields as
> attributes of that object:
>
> opAssoc = Constants(object)
> opAssoc.RIGHT = 0
On 2006-11-01, Paddy <[EMAIL PROTECTED]> wrote:
> Neil Cerutti wrote:
>> The Glk API (which I'm implementing in native Python code)
>> defines 120 or so constants that users must use. The constants
>> already have fairly long names, e.g., gestalt_Version,
>> evtype_Timer, keycode_PageDown.
>>
>> Ca
Ron Adam:
> The disadvantage is an invalid flag may pass silently unless you do some sort
> of
> validation which may slow things down a bit.
That string validation is usually necessary.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Neil Cerutti wrote:
> On 2006-11-01, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>> Neil Cerutti:
>>> scriptref = glk.fileref_create_by_prompt('Transcript+TextMode',
>>>'WriteAppend', 0)
>> That "+" sign seems useless. A space looks enough to me. The
>> functions can accept case-agnostic strin
Neil Cerutti <[EMAIL PROTECTED]> writes:
> Calls to Glk functions are thus ugly and tedious.
>
> scriptref = glk.fileref_create_by_prompt(
> glk.fileusage_Transcript | glk.fileusage_TextMode,
> glk.filemode_WriteAppend, 0)
>
> Please give me some good style advice for t
Tim Chase wrote in news:mailman.1617.1162412498.11739.python-
[EMAIL PROTECTED] in comp.lang.python:
>>> The reason I used instances instead of just the Constants
>>> class was so that I could define a little more descriptive
>>> context for the constants,
>>
>> Sorry I don't know what you mean h
Neil Cerutti wrote:
> The Glk API (which I'm implementing in native Python code)
> defines 120 or so constants that users must use. The constants
> already have fairly long names, e.g., gestalt_Version,
> evtype_Timer, keycode_PageDown.
>
> Calls to Glk functions are thus ugly and tedious.
>
>
>> The reason I used instances instead of just the Constants
>> class was so that I could define a little more descriptive
>> context for the constants,
>
> Sorry I don't know what you mean here, could I have an example
It helps in the recognition if you have separation between
something like
Paul McGuire wrote in news:[EMAIL PROTECTED] in
comp.lang.python:
>>> opAssoc = Constants(object)
>>> opAssoc.RIGHT = 0
>>> opAssoc.LEFT = 1
>> This is nice, but you can cut down on some of the cruft:
>> Constants.LEFT = 1
> One man's cruft is another man's clarity.
:-)
> The reason I used
Rob Williscroft:
> This is nice, but you can cut down on some of the cruft:
>
> class Constants( object ):
> pass
>
> Constants.RIGHT = 0
> Constants.LEFT = 1
>
> ## client code ...
> print Constants.LEFT
Another possibility is to define such constants as strings instead of
integers:
_allflags
"Rob Williscroft" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Paul McGuire wrote in news:[EMAIL PROTECTED] in
> comp.lang.python:
>
>>
>> class Constants(object)
>> pass
>>
>> (I guess value immutability could probably be implemented using clever
>> implementations of __seta
Paul McGuire wrote in news:[EMAIL PROTECTED] in
comp.lang.python:
>
> class Constants(object)
> pass
>
> (I guess value immutability could probably be implemented using clever
> implementations of __setattr__ and such, but is it really worth the
> bother?).
>
> Then I defined the context
On 2006-11-01, Paul McGuire <[EMAIL PROTECTED]> wrote:
> I recently had to add some new constants to pyparsing,
> representing LEFT and RIGHT, but I didn't want to define such
> generic and likely-to-collide-with-user-code variable names.
>
> I settled on defining my own flavor of the Bag class, wh
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Errata:
> opAssoc = Constants(object)
Urk! Should be "opAssoc = Constants()"
> and so on. In the client modules they would simply enter "from glk import
> fileusage, filemode". Or if they just "import glk", the refere
On 2006-11-01, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Neil Cerutti:
>> scriptref = glk.fileref_create_by_prompt('Transcript+TextMode',
>>'WriteAppend', 0)
>
> That "+" sign seems useless. A space looks enough to me. The
> functions can accept case-agnostic strings and ignore spaces
> in
Neil Cerutti:
> scriptref = glk.fileref_create_by_prompt('Transcript+TextMode',
>'WriteAppend', 0)
That "+" sign seems useless. A space looks enough to me. The functions
can accept case-agnostic strings and ignore spaces inside them.
Example:
('transcript textmode ', 'writeappend', 0)
> Pars
"Neil Cerutti" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> The Glk API (which I'm implementing in native Python code)
> defines 120 or so constants that users must use. The constants
> already have fairly long names, e.g., gestalt_Version,
> evtype_Timer, keycode_PageDown.
>
> Ca
17 matches
Mail list logo