我有以下文件夹结构.
application/app/folder/file.py
我想从另一个驻留的Python文件中的file.py中导入一些函数
application/app2/some_folder/some_file.py
我试过了
from application.app.folder.file import func_name
和其他一些尝试,但到目前为止我无法正确导入.我怎样才能做到这一点?
我有一个存储所有.py文件的目录.
bin/
   main.py
   user.py # where class User resides
   dir.py # where class Dir resides
我想在main.py中使用user.py和dir.py中的类.
如何将这些Python类导入main.py?
此外,User如果user.py位于子目录中,如何导入类?
bin/
    dir.py
    main.py
    usr/
        user.py
我对 python 很陌生,并且看过各种堆栈溢出帖子。我觉得这应该有效,但事实并非如此。如何从 python 中的另一个文件导入类?这个文件夹结构
src/example/ClassExample
src/test/ClassExampleTest
我有这门课
class ClassExample:
    def __init__(self):
        pass
    def helloWorld(self):
        return "Hello World!"
我有这个测试课
import unittest
from example import ClassExample
class ClassExampleTest(unittest.TestCase):
    def test_HelloWorld(self):
        hello = ClassExample()
        self.assertEqual("Hello World!", hello.helloWorld())
if __name__ == '__main__':
    unittest.main()
当单元测试运行时,对象为 None:
AttributeError:“NoneType”对象没有属性“helloWorld”
这有什么问题吗?如何在Python中导入类?
我正在使用python3Ubuntu 18.04 并尝试安装名为“”的 python 包pyimagesearch。无法使用pip命令或进行安装apt-get install。我用谷歌搜索如何安装它,但所有的点击都显示了这个链接:
https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/
我按照所有步骤进行操作,没有出现任何错误。为了测试此链接中提到的内容,我做了:
import cv2
它起作用了。然后我尝试:
import pyimagesearch
但我仍然收到此错误:
>>> import pyimagesearch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyimagesearch'
你知道如何安装这个软件包吗?