<jupyter_start><jupyter_text>Introduction to Python VII - Python Modules* by <NAME>* Copyright: Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/  Importing ModulesThe key feature of Python is it's very strom basis of open libraries - called modules in python. To import a module:<jupyter_code>import os
#get module documentation
os.__doc__
#list all methods of the module
dir(os)<jupyter_output><empty_output><jupyter_text>Also see this [list of module attributes](https://www.dummies.com/programming/python/how-to-view-module-content-in-python/)  Calling module methods<jupyter_code>#example: get all system environment variables
os.environ<jupyter_output><empty_output><jupyter_text>Import variants<jupyter_code>#importing a submodule with new name
%matplotlib inline 
import matplotlib.pyplot as plt
plt.plot([1,6,2,9,4,7])
#importing everthing
from matplotlib.pyplot import *
plot([1,6,2,9,4,7])<jupyter_output><empty_output><jupyter_text>**WARNING:** ``import *`` can be very dangerous -> conflicting name spaces. **DON'T DO IT!**   Writing your own module<jupyter_code>#Basically, one can ``import`` any local python file:
import MyPythonScript as myPy#importing MyPythonScript.py
dir(myPy)
myPy.A<jupyter_output><empty_output><jupyter_text>Also see https://docs.python.org/3/tutorial/modules.html for more Details.  Reloading ModulesIf a module changes (during development), it has to be reloades in order to get the changes into effect...<jupyter_code># load the autoreload extension
%load_ext autoreload
# Set extension to reload modules every time before executing code
%autoreload 2
myPy.B<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09801633605600933, 'fraction_numerical': 0.010501750291715286, 'mean_word_length': 6.588495575221239, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '189448', 'license': 'MIT', 'n_tokens_mistral': 560, 'n_tokens_neox': 537, 'n_words': 165, 'path': 'Day_1_Intro/Full_Python_Tutorial_(optinal)/07_modules.ipynb', 'repo_name': 'keuperj/ki-sommer', 'size': '1720'}