01 在同一个文件夹下,调用函数或者类

A.py文件中

def test():
	print('this is test func')

class A:
    def test():
        print('this is a class named A, its func is test() ')
    

B.py文件中

# way 1
from A import test
from A import A

test()

a = A()
a.test()


# way 2
import A
A.test()
a = A.A()
a.test()
02 在不同文件夹下,调用函数或者类

src文件夹与B.py文件在同一目录下,src文件夹下有C.py文件

C.py文件中

def test():
	print('this is test func')

class C:
    def test(self):
        print('this is a class named C, its func is test() ')
        

B.py文件中

from src.C import test
from src.C import C

test()

a = C()
a.test()

相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2021-07-23
  • 2022-02-09
  • 2022-02-09
  • 2021-05-01
  • 2023-02-23
  • 2022-12-23
猜你喜欢
  • 2022-02-05
  • 2022-02-09
  • 2022-02-09
  • 2022-12-23
  • 2021-07-26
  • 2021-09-03
  • 2022-02-09
相关资源
相似解决方案