太久没写python代码了,学机器学习重新拾起python,笔记比较简陋。
参考:mosh python网课
一、导入同一文件夹下其他文件
first.py
def swim():print("swim")def run():print("run")
同一个文件夹下的second.py
from first import swim, runswim()
run()#方法二
import first
first.swim()
最终打印出
swim
run
二、不同文件夹下
- xxx\first.py
- xxx\ecommerce\sales.py
first.py中导入sales.py:
import ecommerce.sales