# 把解決一類問題的模塊放在同一個文件夾里 —— 包
policy.get()
import os
os.makedirs('glance/api')
os.makedirs('glance/cmd')
os.makedirs('glance/db')
l = []
l.append(open('glance/__init__.py','w'))
l.append(open('glance/api/__init__.py','w'))
l.append(open('glance/api/policy.py','w'))
l.append(open('glance/api/versions.py','w'))
l.append(open('glance/cmd/__init__.py','w'))
l.append(open('glance/cmd/manage.py','w'))
l.append(open('glance/db/models.py','w'))
map(lambda f:f.close() ,l)
import glance.api.policy as policy
from dir.glance.api import policy
policy.get()
import sys
sys.path.insert(0,'C:\\Users\\Administrator\\PycharmProjects\\s9\\day21\\dir')
# print(sys.path)
from glance.api import policy
policy.get()
from dir import glance
glance.db.models.register_models('mysql')
glance.api.policy.get()
# 使用絕對路徑 不管在包內部還是外部 導入了就能用
# 不能挪動,但是直觀
from dir import glance
glance.api.policy.get()
# 相對路徑
# 可以隨意移動包 只要能找到包的位置,就可以使用包里的模塊
# 包里的模塊如果想使用其它模塊的內容只能使用相對路徑,使用了相對路徑就不能在包內直接執行了
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
