Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8308
| References | <927fca1e-ca72-4d33-965c-70b812b83d50@glegroupsg2000goo.googlegroups.com> <mailman.301.1308777491.1164.python-list@python.org> <192j4fjo2gskg$.dlg@localhost.localdomain> <87y60tnhaa.fsf@benfinney.id.au> <eszp4cvoh5fb.dlg@localhost.localdomain> |
|---|---|
| Date | 2011-06-24 01:29 +1000 |
| Subject | Re: python 3 constant |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.325.1308842981.1164.python-list@python.org> (permalink) |
On Thu, Jun 23, 2011 at 9:58 PM, Waldek M. <wm@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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
python 3 constant sidRo <slacky2005@gmail.com> - 2011-06-22 11:54 -0700
Re: python 3 constant Noah Hall <enalicho@gmail.com> - 2011-06-22 22:17 +0100
Re: python 3 constant "Waldek M." <wm@localhost.localdomain> - 2011-06-23 08:40 +0200
Re: python 3 constant Ben Finney <ben+python@benfinney.id.au> - 2011-06-23 17:22 +1000
Re: python 3 constant "Waldek M." <wm@localhost.localdomain> - 2011-06-23 13:58 +0200
Re: python 3 constant Ben Finney <ben+python@benfinney.id.au> - 2011-06-23 23:04 +1000
Re: python 3 constant "Waldek M." <wm@localhost.localdomain> - 2011-06-25 12:42 +0200
Re: python 3 constant Chris Angelico <rosuav@gmail.com> - 2011-06-24 01:29 +1000
Re: python 3 constant "Waldek M." <wm@localhost.localdomain> - 2011-06-23 21:56 +0200
Re: python 3 constant Chris Angelico <rosuav@gmail.com> - 2011-06-24 08:00 +1000
Re: python 3 constant "Waldek M." <wm@localhost.localdomain> - 2011-06-25 12:50 +0200
Re: python 3 constant Chris Angelico <rosuav@gmail.com> - 2011-06-25 20:59 +1000
Re: python 3 constant "Waldek M." <wm@localhost.localdomain> - 2011-06-25 13:24 +0200
Re: python 3 constant alex23 <wuwei23@gmail.com> - 2011-06-23 20:04 -0700
Re: python 3 constant "Waldek M." <wm@localhost.localdomain> - 2011-06-25 12:44 +0200
csiph-web