Question by someone coming from C...
Lie.1296 at gmail.com
Mon Jun 9 23:21:49 CEST 2008
On Jun 10, 4:00 am, Skye <spo... at gmail.com> wrote:
> Writing this app in Python, not sure what the "best practice" would
> I want a bitfield global logging level that allows me to turn specific
> debugging modules on and off. If I was doing this in C, I'd just use
> some globals like:
> unsigned int debug_level = 0;
> #define DEBUG_GENERAL 0x0001
> #define DEBUG_CONFIG 0x0002
> #define DEBUG_OPTIONS 0x0004
> etc etc
> So I guess my questions are:
> 1. there doesn't seem to be a way to define global constants like in
> other languages?
Global variables is like this:
-- module.py --
someglobal = 1
# This makes someglobal readonly,
# any attempt to write to someglobal
# would create a new local variable.
someglobal = 2
# this allows you to manipulate the global
> 2. any special voodoo to use bitfields in Python?
That's a not a good idea in Python. In C, it might worth saving some
few bytes of memory especially for embedded application, in python
it's just not worth it, the virtual machine is way huge compared to
the few bytes of space saved.
OK, it is possible to do bitfield manipulation in python:
it's not really worth it
More information about the Python-list