[英]How do I import a file from a folder and its contents in Python 3
I am writing a program in Python 3.6 and I need to import a module and its contents. 我正在用Python 3.6编写程序,我需要导入一个模块及其内容。 The module happens to be inside a folder that I created to keep my files organised.
该模块恰好位于我创建的文件夹中,以使文件井井有条。 The folder is inside site-packages.
该文件夹位于站点包中。 I'd imagine it'd be something like this in one line:
我猜想这会像这样一行:
from folder import module import *
It does not work like this: 它不能像这样工作:
from folder import module
from module import *
from my_folder.module import *
请注意,在my_folder
需要一个__init__.py
文件
尝试
from folder.module import *
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.