為套件加入功能

Python 的軟體工程原則

Adam Spannbauer

Machine Learning Engineer at Eastman

套件結構

套件結構

Python 的軟體工程原則

加入功能

正在 work_dir/my_package/utils.py 作業

def we_need_to_talk(break_up=False):
    """Helper for communicating with significant other"""
    if break_up:
        print("It's not you, it's me...")
    else:
        print('I <3 U!')

正在 work_dir/my_script.py 作業

# Import utils submodule
import my_package.utils

# Decide to start seeing other people
my_package.utils.we_need_to_talk(break_up=True)
It's not you, it's me...
Python 的軟體工程原則

用 __init__.py 匯入功能

正在 work_dir/my_package/__init__.py 作業

from .utils import we_need_to_talk

正在 work_dir/my_script.py 作業

# Import custom package
import my_package

# Realize you're with your soulmate
my_package.we_need_to_talk(break_up=False)
I <3 U!
Python 的軟體工程原則

延伸套件結構

延伸套件結構

Python 的軟體工程原則

延伸套件結構

子套件結構

Python 的軟體工程原則

一起來練習吧!

Python 的軟體工程原則

Preparing Video For Download...