08.1 python基础--包和模块
发布日期:2021-05-14 12:22:30 浏览次数:16 分类:精选文章

本文共 3720 字,大约阅读时间需要 12 分钟。

���������������������������������������������

������

��������� Python ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������

  • ���������������������������������������������������������������������������������������������������������������������
  • ������������������������������������������������������������������������������������
  • ������������������������������������������������������������������������������������������

������������������

  • ������������������������������������������������������.py���������������������
  • ������������������������������������������������������������������������������������������
    • ������������������������������
    • ������������������������������������������������������������������
    • ������������������������������

������������������

  • ���������������������

    import my_module  # ���������my_module���������������.py������
    my_module.my_function()
  • ���������������������

    import my_module as my  # ������������������������������������������
    my.my_function()
  • ������������������

    from my_module import (
    my_function,
    MyClass
    )
    my_function()
    instance = MyClass()
  • ���������������

    from my_module import *  # ������������������������������
  • ������������������������������������

    import sys
    if __name__ == "__main__":
    sys.meta_path.append autocomplete import binder)
    # ���������������������Python������������
    ...

if __name__ == "__main__" ���������

���������������������������������������������������������������������������������������������������

������������������������������������if __name__ == "__main__"���������������������������������������������������������������


������������������������������

������������������

������������������Python ������������������������������

  • ������������������������������
  • ���������Python������������os, sys������
  • ������������������sys.path������������������
  • ������������������

    ���������������������������������

  • ������������������������������������
  • Python officially bundled modules.
  • sys.path���������������������������������������
  • ������������������������sys.path������������������������������������

    import sys
    sys.path.append('../lib') #���������������������
    sys.path.append('~/.local/share/python') #������������������������

    ���

    ������������������������������������������������������������������+������__init__.py���������������������������������������������������������������������������

    ���������������

    my_package/
    ��������� __init__.py
    ��������� module1.py
    ��������� module2.py
    ��������� submodule/
    ��������� __init__.py
    ��������� submodule_module.py

    ������������������������������������������������������������������__init__.py������������������������������

    ���������������

    • ������������������

      import my_package
    • ������������������������

      from my_package import *

    ������������

    ���������������������������������������������������������������������������������������������

    ���������������������

    ���������������������������������������������������������������������������������������������������������������������������

    setName()  
    Student.setName()
    Dog.setName()

    ������������������������������������������������������������������������������������������������������


    ���������������

    • ���������������������������������������������������������������������������������
    • ������������������������������������������������������������������������
    • ���������������������������������������������������������������������������������������

    ���������������������������������������������������������������������������������������������������������������������������������������������������������������

    上一篇:17 python基础--异常处理
    下一篇:16 python基础-恺撒密码

    发表评论

    最新留言

    第一次来,支持一个
    [***.219.124.196]2025年04月25日 04时53分00秒