<jupyter_start><jupyter_text>Using our Python modules in JupyterTo use our Python modules in Jupyter, we need to add let Python know where to find them:<jupyter_code>import sys
sys.path.append("../../../bin") # The path to our bin directory<jupyter_output><empty_output><jupyter_text>Now we can import our module like we would a Python package:<jupyter_code>import analysis<jupyter_output><empty_output><jupyter_text>We can now use functions and classes define in the module:<jupyter_code>analysis.add(10, 20)
analysis.total([1, 2, 3, 4, 5])<jupyter_output><empty_output><jupyter_text>We can also view the documentation that we wrote.For example, the module docstring:<jupyter_code>analysis?<jupyter_output><empty_output><jupyter_text>Also, we can see the docstrings for functions:<jupyter_code>analysis.add?<jupyter_output><empty_output><jupyter_text>Making changes to the module If we make changes to the module, I recommend pressing the "Restart Kernel and Run All Cells" button. This will reimport our module and fix any results that were obtained from running code cells out of order.However, if we really want to reload our module without restarting our notebook, we can use the "AutoReload" Jupyter extension when we import our module:<jupyter_code>%load_ext autoreload
%autoreload 2
import analysis<jupyter_output><empty_output><jupyter_text>Running command line toolsIt's worth mentioning that you can also run command line programs in Jupyter notebooks simply by prefixing commands with `!`:<jupyter_code>!python ../../../bin/analysis.py -h
!python ../../../bin/analysis.py 1 2 3<jupyter_output>INFO: Calculating sum of [1, 2, 3]
INFO: Finished in 0.001019s.
6
{'fraction_non_alphanumeric': 0.08802395209580838, 'fraction_numerical': 0.01437125748502994, 'mean_word_length': 6.233766233766234, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '544697', 'license': 'MIT', 'n_tokens_mistral': 543, 'n_tokens_neox': 514, 'n_words': 188, 'path': 'results/wfondrie/2021-07-14_demo-notebook/demo-notebook.ipynb', 'repo_name': 'Noble-Lab/python-style-demo', 'size': '1670'}