Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Hello World issues when using %% with ipython
#1
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
Quote
#2
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.
Quote
#3
(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
Quote
#4
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.
Quote
#5
(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.
Quote
#6
Running code without % is correct when not using interactive python.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  IPython console vs Spyder script losc 3 281 Apr-30-2020, 04:57 AM
Last Post: deanhystad
  How can I create a multiline input in ipython? DataMower 3 637 Oct-28-2019, 08:50 PM
Last Post: DataMower
  ipython autocomplete broke indentation! Exsul 6 1,014 Aug-20-2019, 01:29 AM
Last Post: Exsul
  Help | Classes to use in real world soothsayerpg 9 752 Jul-08-2019, 07:30 PM
Last Post: nilamo
  How to clear IPython console in Spyder? Vai 7 33,874 Aug-20-2018, 09:43 PM
Last Post: james_balcomb
  Stopwatch in Python/IPython shell suvadip 3 1,578 Jul-06-2018, 01:51 PM
Last Post: snippsat
  PyEDA-IPython Problem [Graph] embash 5 1,352 Jun-02-2018, 06:40 PM
Last Post: buran
  running python hello world Avarage_Joe 8 1,856 Apr-13-2018, 04:20 PM
Last Post: Avarage_Joe
  Hello world! program, window disappears nerio 3 1,384 Mar-16-2018, 07:03 PM
Last Post: knackwurstbagel
  Spyder : Clear IPython Console whenever I re-run the script smallabc 0 2,659 Mar-04-2018, 08:05 AM
Last Post: smallabc

Forum Jump:


Users browsing this thread: 1 Guest(s)