> I'm _very_ used to using C style constants (preprocessor #define
> directives) or C++ const keyword style, for a variety of reasons.
>
> I've yet to see anything covering 'how to work around the lack of
> constants in Python'...can anyone point me in the right direction
here?

Define "Constants" in Upper case letters and don't change anything
that has an uppercase name... Its consistent with Python's
philosophy of us all being consenting adults not idiots...

> still uses the ocal file's namespace.  I don't want to debate the
merits
> of using globals...most people that claim they never use any in
other
> languages _still_ use constants in header files, which is the
purpose
> I'd like to be able to do generally...

THats fine just import the consants module. Using modules avoids
name clashes and is A Good Thing - even for constants.

> really am _not_ thrilled with the use of string literals typed in
each
> time in code (yes, quick and dirty code but still) I see seems to be
> 'OK' in python for the use of comparisons...opposed to something
like
>
> if(strncmp(strVal,
> CONSTANT_STRING_VAL_LIKE_HTTP_ACCEPT_ENCODING_HEADER,
> strlen(strVal)
> {
> do_something();
> }

Not sure whatthe issue is here. You can define string constants
and compare them if you wish. jUst as you can compare string literals
in C... I have a feeling I'm missing your point?

> if(floatVal > PI)
> {
> do_something()
> }

Again, not sure what the issue is.
Use math.pi as a constant, whats the issue?

> A last question would also be if the equivalent of __FILE__ and
__LINE__
> macros exist?

Sadly not, that's one thing I would like to see. It is possible to
fake
it via traceback objects but its mucky. You can get file fairly easily
via the __Name__ magic variable but line number is trickier.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to