在Ipython中运行/导入脚本

2024-04-19 12:14:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我想写个剧本(OutputVariables.py)在IPython的主文件中。 我的主文件包括以下几行:

import numpy as np # first line
import math        # second line    
run OutputVaribles # third line

当按F5时,run命令出现语法错误(无效语法)。如果我分别选择每一行并按F9,它将运行脚本。类似地,在控制台中实现runoutputVariables也可以。有人能告诉我这里怎么了吗?在

注意:我的主文件和OutputVariables.py文件在同一个方向。我安装了水蟒。我使用Spyder作为我的编辑器,并在IPython控制台中进行编译。在


Tags: 文件runpyimportnumpyasipythonnp
1条回答
网友
1楼 · 发布于 2024-04-19 12:14:17

你能试着在一个函数中写你想在OutputVaribles.py中运行的代码,然后在main.py中导入并调用该函数吗?在

输出变量.py

def your_function():
    # your code block here

主.py

^{pr2}$

然后可以使用执行main.py

python main.py

在你的控制台里。在

相关问题 更多 >