C macros in Python.

Quinn Dunkan quinn at zloty.ugcs.caltech.edu
Tue Oct 17 16:26:33 EDT 2000


On Tue, 17 Oct 2000 11:30:35 +0100, Burkhard Kloss <bk at xk7.com> wrote:
>> On a different, but related, topic...I sometimes miss C's #define
>> macro.  There doesn't seem to be any similar thing in Python capable of
>> creating identifiers which are 1) constant, that is, "read only", and 2)
>> truly global in scope.
>How about defining a function that returns the value?  that would make it
>nicely read-only.
>
>define pi(): return 3.14....

pi = 3

will defeat that nicely.


If you want something to be constant in python, don't reassign it.  Not that
hard, now is it? :)  And if you want something "truly global" you could shove
it into __builtins__, which is great not only for confusing other people but
also increasing job security.  And that's why you want globals in the first
place, right? :)

Or, you could just run all your python scripts through cpp.



More information about the Python-list mailing list