[英]Import with dot name in python
How can I import a dotted name file in python?如何在python中导入带点名称的文件?
I don't mean a relative path, but a filename starting or containing a dot "."
我不是指相对路径,而是指以点"."
开头或包含点"."
的文件名"."
For example: '.test.py'
is the filename.例如: '.test.py'
是文件名。
import .test
will search for a test
package with a py
module in a parent package. import .test
将在父包中搜索带有py
模块的test
包。
The situation is tricky, because dots mean subpackage structure to python.情况很棘手,因为点表示 python 的子包结构。 Never the less it is still kinda possible with imp
:无论如何,使用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.注意:这是非正统的,建议您简单地重命名模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.