import os from cenviron import getenvputenv class envwrapperdef __setattr__(selfnamevalue)os environ[namevalue putenv(namevaluedef __getattr__(selfname)value getenv(nameos environ[namevalue return value env envwrapper(get module' methods wrap in python class on writesenv name=value put in os environ too on readsenv name integrity check make one instance the following shows our python wrappers running atop our extension module' functions to access environment variables the main point to notice here is that you can graft many different sorts of interface models on top of extension functions by providing python wrappers in addition to extensionsfrom envmap import env env['user''skipperenv['user''professorenv['user''professorfrom envattr import env env user 'professorenv user 'gilliganenv user 'gilliganwrapping environment calls with swig you can manually code extension modules like we just didbut you don' necessarily have to because this example really just wraps functions that already exist in standard librariesthe entire cenviron code file in example - can be replaced with simple swig input file that looks like example - example - pp \integrate\extend\swig\environ\environ /**************************************************************swig module description fileto generate all python wrapper code for lib getenv/putenv calls"swig -python environ ***************************************************************%module environ extern char getenv(const char *varname)extern int putenv(char *assignment) python/ integration