Import with dot name in python

2019-01-23 08:25发布

How can I import a dotted name file in python?

I don't mean a relative path, but a filename starting or containing a dot "."

For example: '.test.py' is the filename.

import .test will search for a test package with a py module in a parent package.

标签: python import
1条回答
Bombasti
2楼-- · 2019-01-23 08:45

The situation is tricky, because dots mean subpackage structure to python. Never the less it is still kinda possible with imp:

import imp
my_module = imp.load_source('my_module', '.test.py')

note: this is unorthodox and you are recommend to simply rename your modules instead.

查看更多
登录 后发表回答