在Python中,导入本地脚本的方法如下:
导入同一个目录下的脚本
```python
import useful_functions
使用别名
```python
import useful_functions as uf
避免执行导入脚本中的可执行语句
```python
if __name__ == "__main__":
导入的脚本中的可执行语句应该放在这里
导入父目录下的脚本
```python
import sys
import os
sys.path.append(os.path.pardir) 添加父目录到路径
import other_script
使用from...import...语句
```python
from useful_functions import add_five
在框架项目中导入模块
```python
from os.path import dirname, abspath
from user import models as user_models