Python Forum
Code runs as pure python but not jupyter notebook
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code runs as pure python but not jupyter notebook
#2
This code runs fine on Jupyter. However, you will get 'invalid syntax' if you try print quicksort([3, 6, 8, 10, 1, 2, 1]). You have to print(quicksort([3, 6, 8, 10, 1, 2, 1])) because you probably have Python 3 kernel (have a look at Installing the IPython kernel)

You don't need 'print' to have cell output. Just enter 'quicksort([3, 6, 8, 10, 1, 2, 1])' in cell and hit shift + enter.

By default you will have output of last expression in cell:

1 + 1
1 + 2
Output:
3
If you want to have all outputs of expressions in cell at once then you have to run:

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
After that you will have output of all expressions in cell (previous example will produce 2 and 3) without need of 'print'.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: Code runs as pure python but not jupyter notebook - by perfringo - Aug-22-2018, 05:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm trying to import a dataset into a Jupyter Notebook Hisilat03 0 720 Mar-24-2025, 09:26 AM
Last Post: Hisilat03
  Jupyter Notebook cell ? flaviu2 6 4,929 Feb-10-2025, 09:39 AM
Last Post: mysqlguider
  import data (.csv) into Jupyter notebook oranstprotonme 2 1,191 Aug-14-2024, 07:08 PM
Last Post: oranstprotonme
  Troubleshooting Jupyter Notebook installation with Python using pip and a venv Drone4four 1 2,072 Jun-04-2024, 10:55 PM
Last Post: Drone4four
  Install python 2.7 in jupyter lab raman 28 5,234 Jun-01-2024, 01:53 PM
Last Post: snippsat
  problem program runs in a loop jasserin 0 792 May-18-2024, 03:07 PM
Last Post: jasserin
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 4,172 Nov-15-2023, 06:56 PM
Last Post: jst
  Navigating file directories and paths inside Jupyter Notebook Mark17 5 8,091 Oct-29-2023, 12:40 PM
Last Post: Mark17
  How to programmatically stop a program in Jupyter Notebook? Mark17 11 59,663 Feb-12-2023, 01:41 PM
Last Post: jp21in
Thumbs Up Python 3 Jupyter notebook ternary plot data nicholas 0 1,822 Jan-21-2023, 05:01 PM
Last Post: nicholas

Forum Jump:

User Panel Messages

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