[Python-Dev] APIs for internal flags

M.-A. Lemburg mal@lemburg.com
Wed, 12 Jul 2000 10:36:38 +0200


Guido van Rossum wrote:
> 
> > Yes... I meant: it is not available from Python. (mx.Tools
> > publishes an interface to this flag: sys.verbosity() which
> > also allows setting the value at runtime.)
> 
> It would make a lot of sense for the sys module to allow access to the
> values of all the Python command line options, and perhaps to allow
> changing them.
> 
> Anybody interested in designing an API here?  Some requirements would
> be platform independence, extensibility, and necessarily the ability
> to work even in an environment without command line flags (since it
> still has the corresponding internal flags).

For starters, here's what mx.Tools defines:

      sys.verbosity([level]) 
         If level is given, the value of the interpreter's verbosity flag is set to level and the previous value of
         that flag is returned. Otherwise, the current value is returned. 

         You can use this function to e.g. enable verborse lookup output to stderr for import statements even
         when the interpreter was not invoked with '-v' or '-vv' switch or to force verbosity to be switched off. 

      sys.debugging([level]) 
         If level is given, the value of the interpreter's debugging flag is set to level and the previous value of
         that flag is returned. Otherwise, the current value is returned. 

         You can use this function to check whether the interpreter was called with '-d' flag or not. Some
         extensions use this flag to enable/disable debugging log output (e.g. all the mx Extensions).

     sys.optimization([level]) 
         If level is given, the value of the interpreter's optimization flag is set to level and the previous value of
         that flag is returned. Otherwise, the current value is returned. 

         You can use this function to e.g. compile Python scripts in optimized mode even though the interpreter
         was not started with -O. 

Perhaps a more generic interface would be nicer, but given
that not all flags are really useful and some of them may
not be altered after initialization, I find the per flag
interfaces fit rather well (they also have the advantage of
being able to add code on a per flag basis, which may become
useful for future additions).

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/