0

I have a question, is it possible to save a created function like shown in the picture "Created function inside the shell" to the shell itself, so that I can call this function even after I closed the shell and re-opened it ?

Created function inside the shell

flaxel
  • 4,173
  • 4
  • 17
  • 30
  • You should write python code in a `.py` file. – quamrana Apr 07 '21 at 07:40
  • you can write packages, and the packages can later be imported and called like ```import datetime; print(datetime.datetime.now())``` – Kristian Apr 07 '21 at 07:41
  • this might help you, you can create a file with your function, and that file will be run every time you open the python shell https://stackoverflow.com/questions/11124578/automatically-import-modules-when-entering-the-python-or-ipython-interpreter – Ron Serruya Apr 07 '21 at 07:43
  • 1
    In IPython, you can use profiles and save the code into e.g. `~/.ipython/profile_default/startup`. It will run in the beginning of each shell session. – bereal Apr 07 '21 at 07:44

1 Answers1

-1

You can write the code in python file and save the code.

def hello_print():
   print("Hello")

Save above code in python file i.e., hello_world.py

And then run the file using following command in CMD:

python hello_world.py

later if you want to use the function in another code then you can import the function as follows:

from hello_world import hello_world
Rushabh Sudame
  • 414
  • 1
  • 6
  • 22