Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm: sharing objects with a notebook

Context

I'm new to Pycharm and I've seen we can use Jupyter notebooks (aka Ipython) within Pycharm.

Question

If I use a Python script/console and a Jupyter notebook at the same time in Pycharm, is it possible to make them sharing the objects ?

Example :

  1. From my python script I execute a = 2
  2. From the notebook I execute a
  3. It returns 2
like image 538
Ricol Avatar asked Jan 28 '26 20:01

Ricol


1 Answers

Maybe I am confused by your question, but can you not just use the "run" command in the iPython terminal to do what you are asking?

Say I have a python script named myscript.py. In that script, I define a = 2.

# This is myscript.py. It is located where you will invoke iPython
a = 2

If the script runs with no errors (hopefully just a variable declaration would :P) you should be able to do the following:

In [2]: run pythontest.py

In [3]: a
Out[3]: 2

If that is it, great! But I feel like I am missing some context to your question because that seems like it may be a bit too easy :).

like image 172
Kush Avatar answered Feb 01 '26 10:02

Kush