简体   繁体   中英

Can't use imported functions in Python 2.7

Every time I attempt to run this on 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 is an IPython magic command.

"/var/folders/mw/h485shnx75dg6f4z_xvcg5hm0000gn/T/tmpcjJKuI.py" is the location of your script on disk. 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. In other words, you should check the numpy documentation for what you want to accomplish

1) The Python panel in the Canopy GUI application is an IPython QtConsole. IPython provides various "magic" commands which can be entered in the Python panel even though they are not actual Python statements. One such magic command is the %run command, which will run the specified file. 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.

You typed your code into the Canopy editor, but you did not save it with a filename. So when you "run" the, it auto-saves as a temporary file, and runs that temporary file, as @cricket_007 points out.

2) As @cricket_007 points out, your arange call is incorrect. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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