Can't do a multiline assignment!

colas.francis at gmail.com colas.francis at gmail.com
Thu Apr 17 12:35:10 EDT 2008


On 17 avr, 18:19, s0s... at gmail.com wrote:
> On Apr 17, 10:54 am, colas.fran... at gmail.com wrote:
>
> > On 17 avr, 17:40, s0s... at gmail.com wrote:
>
> > Out of sheer curiosity, why do you need thirty (hand-specified and
> > dutifully commented) names to the same constant object if you know
> > there will always be only one object?
>
> I'm building a web server. The many variables are names of header
> fields. One part of the code looks like this (or at least I'd like it
> to):
>
> class RequestHeadersManager:
>
>     # General header fields
>     Cache_Control               = \
>     Connection                  = \
>     Date                        = \
>     Pragma                      = \
>     Trailer                     = \
>     Transfer_Encoding           = \
>     Upgrade                     = \
>     Via                         = \
>     Warning                     = \
>
>     # Request header fields
>     Accept                      = \
>     Accept_Charset              = \
>     Accept_Encoding             = \
>     Accept_Language             = \
>     Authorization               = \
> ...
>
> Etc etc etc. At the end they'll all be assign to None. Then, when
> initialized, __init__() will the the string of headers, parse them,
> and use those variables shown above to assign to the header values. Of
> course a normal request won't include all of those headers, so the
> others will remain None. That's what I want.

Ah, so they are not constant, I was mislead by the name 'CONSTANTn' in
your OP.

But why would you insist on:
"""
# helpful comment
CONSTANT1 = \
# there too
CONSTANT2 = \
CONSTANT3 = \
None
"""
rather than:
"""
# helpful comment
CONSTANT1 = None
# there too
CONSTANT2 = None
CONSTANT3 = None
"""
or even:
"""
CONSTANT = None
# helpful comment
CONSTANT1 = CONSTANT
# there too
CONSTANT2 = CONSTANT
CONSTANT3 = CONSTANT
"""

(hopefully you don't consider those names in your code. ^ ^)



More information about the Python-list mailing list