How can module determine its own path?
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Fri Oct 30 22:17:45 EDT 2009
On Fri, 30 Oct 2009 20:08:28 -0500, Robert Kern wrote:
> Stef Mientki wrote:
...
>> but how do I configure a "properly initialized namespace dict" (other
>> than my current namespace) ?
>
> filename = '...'
> ns = dict(
> __file__=filename,
> __name__='whatever_you_need_it_to_be', __builtins__=__builtins__,
> )
> execfile(filename, ns)
Or better still, don't use execfile at all, and just use the import
system the way it's supposed to be used. If you find yourself doing by
hand what the Python compiler normally does for you, it's a good sign
that you're probably doing it wrong.
--
Steven
More information about the Python-list
mailing list