zoukankan      html  css  js  c++  java
  • python(34)- 模块与包练习

    创建如下目录结构
    keystone/
    ├── __init__.py
    └── auth
        ├── __init__.py
        └── plugins
            └── core.py

    core.py内容为:

        def create():
            print("create函数被调用")



        class UserAuthInfo:

            def __init__(self):
                self.password = None

    要求一:保证包keystone可以在任意位置被导入
    要求二:import keystone,然后就可以直接调用keystone.create和keystone.UserAuthInfo

    #keystone目录下的__init__文件
    
    from .auth.plugins.core import create
    from .auth.plugins.core import UserAuthInfo
    
    import sys,os
    base_dir=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    sys.path.append(r"base_dir")
    
    #test文件,处于任意路径运行结果均相同
    
    import keystone
    keystone.create()
    --->create函数被调用
    
    print(keystone.UserAuthInfo)
    ---><class 'keystone.auth.plugins.core.UserAuthInfo'>
    

    详细请参考博客末尾内容,单独调用包。http://www.cnblogs.com/xuyaping/p/6797032.html

  • 相关阅读:
    [LUOGU] P3275 [SCOI2011]糖果
    [BZOJ] 2287: 【POJ Challenge】消失之物
    [BZOJ] 2131: 免费的馅饼
    [JZOJ] 5835. Prime
    [JZOJ] 5837.Omeed
    UF_CAMGEOM_ask_custom_points 封装缺陷
    NX Open 切削层加载
    NX Open 图层说
    c++ Dll调用
    VC操作Excel文件编程相关内容总结
  • 原文地址:https://www.cnblogs.com/xuyaping/p/6802608.html
Copyright © 2011-2022 走看看