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

  • 相关阅读:
    hadoop
    spark
    docfetcher
    redis参考资料
    Redis系列-存储篇sorted set主要操作函数小结
    predis操作大全
    composer安装使用
    寒假作业2
    寒假作业随笔
    面向对象寒假作业编程题
  • 原文地址:https://www.cnblogs.com/xuyaping/p/6802608.html
Copyright © 2011-2022 走看看