Azure Setup and Account Access
Organizing code into functions and modules is essential for building maintainable data pipelines.
You learned functions in Core. Here's what's important for data engineering:
def clean_value(value: str, default: str = "") -> str:
"""Clean and normalize a string value.
Args:
value: The string to clean
default: Value to return if input is empty
Returns:
Cleaned string, lowercase and stripped
"""
if not value:
return default
return value.strip().lower()
<aside> 💡 Always write docstrings. They help your future self and teammates.
</aside>
A module is simply a .py file. You can import functions from it.
# `utils.py`
def clean_value(value):
return value.strip().lower()
# `main.py`
from utils import clean_value
print(clean_value(" HELLO "))
__name__ == "__main__" PatternThis pattern lets a file work both as a module AND as a script:
# `utils.py`
def clean_value(value):
return value.strip().lower()
if __name__ == "__main__":
# Only runs when executed directly
print(clean_value(" TEST "))
<aside> ⌨️ Hands-on: Create utils.py with a function, import it in main.py.
</aside>
if __name__ == "__main__": block allow a script to do?utils.py with a function clean(), how do you import and use it in main.py?Next lesson: Type Hints
The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0

Found a mistake or have a suggestion? Let us know in the feedback form.