简体   繁体   English

不能在 Python 2.7 中使用导入的函数

[英]Can't use imported functions in Python 2.7

Every time I attempt to run this on Canopy.每次我尝试在 Canopy 上运行它时。

import numpy as np

import matplotlib.pyplot as plt 

y = np.arange(10.0, 0.0, 0.5)

print(y)

I get:我得到:

%run "/var/folders/mw/h485shnx75dg6f4z_xvcg5hm0000gn/T/tmpcjJKuI.py" [] %run "/var/folders/mw/h485shnx75dg6f4z_xvcg5hm0000gn/T/tmpcjJKuI.py" []

%run is an IPython magic command. %run是一个 IPython 魔法命令。

"/var/folders/mw/h485shnx75dg6f4z_xvcg5hm0000gn/T/tmpcjJKuI.py" is the location of your script on disk. "/var/folders/mw/h485shnx75dg6f4z_xvcg5hm0000gn/T/tmpcjJKuI.py"是你的脚本在磁盘上的位置。 You probably have not saved this to a file anywhere else, hence the random location.您可能没有将其保存到其他任何地方的文件中,因此是随机位置。

[] is the arguments that are passed into the script. []是传递到脚本中的参数。 You have none, so this is an empty list.你没有,所以这是一个空列表。


All in all, I think you're looking for the output in the wrong place.总而言之,我认为您正在错误的地方寻找输出。

Or simply nothing is printed because you have defined start=10.0, stop=0.0 , but the step is positive.或者只是没有打印任何内容,因为您已经定义了start=10.0, stop=0.0 ,但是步骤是正的。 In other words, you should check the numpy documentation for what you want to accomplish换句话说,您应该检查 numpy 文档以了解您想要完成的工作

1) The Python panel in the Canopy GUI application is an IPython QtConsole. 1) Canopy GUI 应用程序中的 Python 面板是一个 IPython QtConsole。 IPython provides various "magic" commands which can be entered in the Python panel even though they are not actual Python statements. IPython 提供了各种“魔法”命令,即使它们不是实际的 Python 语句,也可以在 Python 面板中输入。 One such magic command is the %run command, which will run the specified file.一个这样的神奇命令是%run命令,它将运行指定的文件。 Canopy's "Run" command simply executes the IPython %run command, which is why that command appears in the Python console as soon as you "Run" your file. Canopy 的“运行”命令只是执行 IPython %run 命令,这就是为什么只要“运行”文件,该命令就会出现在 Python 控制台中。

You typed your code into the Canopy editor, but you did not save it with a filename.您在 Canopy 编辑器中输入了代码,但没有使用文件名保存它。 So when you "run" the, it auto-saves as a temporary file, and runs that temporary file, as @cricket_007 points out.因此,当您“运行”时,它会自动保存为临时文件,并运行该临时文件,正如@cricket_007 指出的那样。

2) As @cricket_007 points out, your arange call is incorrect. 2) 正如@cricket_007 指出的那样,您的arange调用不正确。 You have mixed up the order of arguments, so the result is an empty array, which prints as []您混淆了参数的顺序,因此结果是一个空数组,打印为[]

I suggest that you do lots of experimentation.我建议你做很多实验。 You'll learn a lot and you won't break anything.你会学到很多东西,你不会破坏任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM