Easy questions from a python beginner

Alf P. Steinbach /Usenet alf.p.steinbach+usenet at gmail.com
Sun Jul 11 15:37:28 EDT 2010


* Stephen Hansen, on 11.07.2010 21:00:
> On 7/11/10 11:45 AM, wheres pythonmonks wrote:
>> Follow-up:
>> Is there a way to define compile-time constants in python and have the
>> bytecode compiler optimize away expressions like:
>>
>> if is_my_extra_debugging_on: print ...
>>
>> when "is_my_extra_debugging" is set to false?  I'd like to pay no
>> run-time penalty for such code when extra_debugging is disabled.
>
> Any code wrapped in a __debug__ guard is utterly ommitted if you run
> Python with the -O option. That, and asserts go away.
>
>> On #2:  My point regarding the impossibility of writing the swap
>> function for ints is to explicitly understand that this isn't
>> possible, so as not to look for solutions along those lines when
>> trying to write python code.
>
> Its impossible because Python's calling and namespace semantics simply
> don't work like that. There's no references in the traditional sense,
> because there's no variables-- boxes that you put values in. There's
> just concrete objects. Objects are passed into the function and given
> new names; that those objects have names in the enclosing scope is
> something you don't know, can't access, and can't manipulate.. even the
> objects don't know what names they happen to be called.
>
> Check out http://effbot.org/zone/call-by-object.htm

Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python works like 
Java in this respect, that's all; neither Java nor Python support 'swap'.

Of course there are variables, that's why the docs call them variables.

We've had this discussion before and I know from that that it is a religious 
issue with a small subset of the Python community, where reason, facts, logic 
does not apply and is not even recognized as such. So be it. So I'm not out to 
convince you or other of that sub-community, or trying to reason with you folks 
on this issue (futile, and generates flames pretty fast), but I do not want 
newbies brainwashed into that non-reasoning nonsense pure faith religion.

For what it's worth, I'm sure that the effbot.org author, whose pages are 
otherwise quite technically meaningful & useful, in this case, after the flame 
war with some Java folks, decided that technical accuracy just wasn't worth it.

So, I believe, he punted, which is an eminently rational choice when one's goals 
require acceptance in a society dominated by a religious clique. And just as I'm 
not out to engage you in any debate on this issue (futile), neither am I calling 
you irrational. Perhaps your choice is the same as that author's.


Cheers,

- Alf

-- 
blog at <url: http://alfps.wordpress.com>



More information about the Python-list mailing list