如何使用包之间的调用

1. 首先新建一个包 package

 

 2. 新建一个文件, 文件中包含类

 

class Calculator:
    def add(self,a,b):
        return a + b
    def div(self,a,b):
        return a / b

 

 

 3. 新建一个调用这个类的文件

from pythoncode.Calculator import Calculator


class TestCalculator:
    def test_add(self):
        calc = Calculator ()
        assert 2 == calc.add(1,1)

 

 

 3. 使用terminal执行的时候, 可能会提示找不到module

 

 4. 

前面加上 

import sys
sys.path.append("..")
就可以了。

 

posted @ 2021-12-30 10:59  feifei_tian  阅读(85)  评论(0编辑  收藏  举报