2

I forked a repo from github and copied to my local machine and opened all the files in Jupyter. Now I have access to all the .py files and all the notebooks.

Let's say I want to add a new function to the package as follows:

teste(self):
   return self

I do this by writing the function in the here.py file and to make sure it works I test it on a notebook by calling it in a cell and executing that cell:

print(here.teste(worked)) 

However, this doesn't work. My guess is that I have not updated the package itself so the function teste() does not exist. How do I commit this change to the package locally (without using pull request).

Jurgen Strydom
  • 3,540
  • 1
  • 23
  • 30
Kzards
  • 23
  • 4
  • You probably want to enable auto-reload so that the changes in python modules are reflected in the IPython kernel that you run in the notebook see: https://stackoverflow.com/questions/5364050/reloading-submodules-in-ipython – krassowski May 20 '21 at 15:53
  • Check this solution: https://stackoverflow.com/questions/32234156/how-to-unimport-a-python-module-which-is-already-imported – Jurgen Strydom May 21 '21 at 09:55

1 Answers1

1

Most likely you need to restart your jupyter kernel for the changes to take effect.

Git is merely a versioning system, it does not care what python does and does not influence how python works.

Python loads your package when it is imported import my_package as mp. When you make changes to that package while python is running, it is not aware of those changes. If you try to re-import, python will merely check if it is already imported (which is true) and do nothing. So the changes still does not take effect. Only when you restart the kernel, and import the package will it take effect. You can also re-import a package with the following (python 3.4 and greater):

import importlib
importlib.reload(package)
Jurgen Strydom
  • 3,540
  • 1
  • 23
  • 30