I agree that there are similar questions,but none serve my purpose.
I can neither change the file name nor add a symlink. The file name is significant.
I have tried the following
>>> imp.load_source('test','.')
<module 'test' from '.'>
and
>>> importlib.import_module('test','.')
<module 'test' from '.'>
Where the module test
is just
print 'hello world'
test.py
,that is,prints hello world
upon import.Is there any way to "run" the module imported by using imp or imortlib?
I would like to add that I am talking about a control
file in the autotest project,if it matters.
You can use imp.load_source
>>> import imp
>>> mod = imp.load_source("test", "test")
hello world
>>> mod.a
1
abc:
print "hello world"
a = 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With