Python equivalent for C module

Derek Martin code at pizzashack.org
Mon Oct 20 17:09:25 EDT 2008


On Mon, Oct 20, 2008 at 07:29:16PM +0200, Bruno Desthuilliers wrote:
> This should have been:
> 
>     fprintf(STDERR, "DEBUG: %s", msg);

No, it shouldn't have.  If I turn on debugging, I  want the debug
messages to go to stdout, so that they can be captured along with the
output (of which there is almost none anyway) to clearly indicate when
they happened.

> STDOUT is for *normal* program outputs. Debug informations, warnings, 
> and all verbosity should go to STDERR.

That's your opinion, and I disagree.  Besides which, if you're running
a program in debug mode, you're DEBUGGING... "normal" does not apply.
You're being rather presumptuous... you don't even know how my program
is being used.

> >Then in the modules that wanted to use it, I did:
> >
> >from debug import DEBUG, dprint
> >But I got some weird behavior.  The imported copy
> 
> It's not a copy.

Actually, I'm pretty sure it is; i.e. there are two copies of the
name: one in the namespace of the module, and one in the namespace of
the file into which I imported it.  At the time they are created, they
both point to the same object.  Is that not the very definition of a
copy?  The object itself may exist only in one place, but it has two
names; one in each namespace. 

> >of DEBUG is
> >read-only;
> 
> It's not read-only.

The *object* very much is: it is immutable.  The name of that object
is DEBUG, and thus DEBUG is read-only.  You can make DEBUG point to a
different object by binding a different value to it, but if that value
is of an immutable type, it will still be a read-only object.

In the sentence I wrote, as well as in general, "DEBUG" actually
refers to two different things: the object bound to the name, and the
name itself.  It's up to the reader to infer which sense is correct
given the thing being said about it.  It just so happens that the
English sentence I wrote refers to both simultaneously.

> Just use a fully qualified name, so you dont make DEBUG local:
> 
> import debug
> print debug.DEBUG
> debug.DEBUG = True
> print debug.DEBUG

Right, several people have already pointed this out.  Which leads me
to believe that the point of your reply was to berate me into
following your conventions, which I have no interest in doing, in part
because they are counterproductive to my goals, and in part because
they are counter to the way I've been programming for 25 years.
Fortunately, it's not your call how I write my code.

> Now note that ALL_UPPER names are - by convention - considered 
> 'constants'. If this is supposed to be altered, don't write it ALL_UPPER.

YOUR convention, not mine.

> Also and FWIW, Python has a logging module in it's stdlib. Please use it 
> instead of any half-backed squared-wheel homegrown solution.

Note that the correct possessive form of "it" is "its" with no
apostrophe.  This was the only thing of value which you contributed,
though really, using that is way overkill for my needs.  If I've
written bad code, by all means, please correct it.  If I've written
code in a style that you happen not to like, please feel free to keep
that to yourself.

> My 2 cents

Must be Zimbabwe currency...

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20081020/093f10b9/attachment-0001.sig>


More information about the Python-list mailing list