Python Forum
Hello World issues when using %% with ipython
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
Reply
#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.
Reply
#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
Reply
#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.
Reply
#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.
Reply
#6
Running code without % is correct when not using interactive python.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  IPython errors for numpy array min/max methods muelaner 1 508 Nov-04-2023, 09:22 PM
Last Post: snippsat
  Can a program execute code in iPython shell and get result? deanhystad 3 1,661 Jun-17-2022, 03:45 AM
Last Post: Larz60+
  Hello World! rufenghk 0 933 Jun-02-2022, 09:48 PM
Last Post: rufenghk
  Very new to Python world daveseaman 0 1,452 Jun-25-2021, 07:17 PM
Last Post: daveseaman
  IPython console vs Spyder script losc 3 2,672 Apr-30-2020, 04:57 AM
Last Post: deanhystad
  How can I create a multiline input in ipython? DataMower 3 4,307 Oct-28-2019, 08:50 PM
Last Post: DataMower
  ipython autocomplete broke indentation! Exsul 6 4,467 Aug-20-2019, 01:29 AM
Last Post: Exsul
  Help | Classes to use in real world soothsayerpg 9 4,060 Jul-08-2019, 07:30 PM
Last Post: nilamo
  How to clear IPython console in Spyder? Vai 7 55,668 Aug-20-2018, 09:43 PM
Last Post: james_balcomb
  Stopwatch in Python/IPython shell suvadip 3 4,207 Jul-06-2018, 01:51 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020