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

 

posted @ 2016-05-03 23:38  许二哈哈哈  阅读(460)  评论(0编辑  收藏  举报