Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71904

Re: All-numeric script names and import

Date 2014-05-22 12:51 +0200
From Xavier de Gaye <xdegaye@gmail.com>
Subject Re: All-numeric script names and import
References <CAPTjJmoadqpS0O-15We7xi7SzFCVxTFe1TU8hConcGZzxTRdcA@mail.gmail.com> <537DD23C.1090301@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.10229.1400780259.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 05/22/2014 12:32 PM, Xavier de Gaye wrote:
 > import 1.py as module_1 on Python 2.7 (module_1 is not inserted in sys.modules):
 >
 >  >>> import imp
 >  >>> module_1 = imp.new_module('module_1')
 >  >>> execfile('1.py', module_1.__dict__)
 >  >>> del module_1.__dict__['__builtins__']


Oups.. should not remove the builtins and should add __file__.
With corrections:

 >>> import imp
 >>> module_1 = imp.new_module('module_1')
 >>> execfile('1.py', module_1.__dict__)
 >>> module_1.__file__ = '1.py'

Xavier

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: All-numeric script names and import Xavier de Gaye <xdegaye@gmail.com> - 2014-05-22 12:51 +0200

csiph-web