Hello World issues when using %% with ipython - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Hello World issues when using %% with ipython (/thread-1180.html) |
Hello World issues when using %% with ipython - landlord1984 - Dec-11-2016 In [44]: %%python3 hello.py ...: UsageError: %%python3 is a cell magic, but the cell body is empty. In [45]: %%python3 hello.py ...: d ...: Hello World ----------------Above is what displayed on ipython. It is weird I type"%%python3 hello.py" and ENTER, error message comes out. But, if I typed something, e.g. "d" after ENTER, and then ENTER again, my "Hello World" is printed from hello.py. Why? Thanks. L RE: Hello World issues - Yoriz - Dec-11-2016 Magic functions Cell magics are prefixed with a double %%, and they are functions that get as an argument not only the rest of the line, but also the lines below it in a separate argument. RE: Hello World issues when using %% with ipython - landlord1984 - Dec-11-2016 (Dec-11-2016, 10:29 AM)Yoriz Wrote: Magic functions Cell magics are prefixed with a double %%, and they are functions that get as an argument not only the rest of the line, but also the lines below it in a separate argument. So what command do I need to use if I have no argument? I have tried "%%python","%%python2" and "%%pypy". None of them just works by ENTER. Thanks, L RE: Hello World issues when using %% with ipython - Yoriz - Dec-11-2016 Why are you typing %% if you don't want to use that functionality just remove it. Read the documentation on what things are rather then just using them blindly. RE: Hello World issues when using %% with ipython - landlord1984 - Dec-11-2016 (Dec-11-2016, 08:00 PM)Yoriz Wrote: Why are you typing %% if you don't want to use that functionality just remove it. Read the documentation on what things are rather then just using them blindly. Ok. The correct command I should type is " %run hello.py". I was misled by an online video, who uses "python hello.py" in ipython to run and it works for him. RE: Hello World issues when using %% with ipython - Yoriz - Dec-11-2016 Running code without % is correct when not using interactive python. |