python 3 constant

Chris Angelico rosuav at gmail.com
Thu Jun 23 11:29:38 EDT 2011


On Thu, Jun 23, 2011 at 9:58 PM, Waldek M. <wm at localhost.localdomain> wrote:
> Of course, it is just my personal opinion. It might be not pythonic,
> I may be wrong, yet - concept of constants is not something new and
> if other languages, like C/C++/Java/Perl/ (bash even) have them,
> I can't see the reason not to have them in Python.
>

You can have them in Python. Just run your code through cpp (the C
preprocessor) first. Voila!

It's handy for other things too. Don't like Python's lack of "then"
and "end if"?

#define then :
#define end(x)

lst=[1,2,3]
if lst then
  do_stuff
end(if)

You can even make functions that take reference arguments!

#define inc(x) x=x+1

i=3
inc(i)
print("i = ",i)
j=4
inc(i+j)
print("i + j = ",i+j

This is an excellent technique, and I heartily recommend it.

Assuming you're writing an entry for the International Obfuscated
Python Code Contest, that is.

ChrisA



More information about the Python-list mailing list