I have a python file called
default.properties.py
How can I successfully import it as a module, I tried
import default.properties as prop
but it didn't work until I changed the name to default.py, Id like to keep the name with two extensions, is this possible?
You can use imp
import imp
mymodule = imp.load_source('default.properties','default.properties.py')
>>>mymodule.variable
"i am variable in default.properties.py"
OR
mymodule = imp.load_module('default.properties',
open('default.properties.py'),
os.path.abspath('default.properties.py'),
('.py', 'r', imp.PY_SOURCE))
>>>mymodule.variable
"i am variable in default.properties.py"
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