python - from ..xxxx import xxxx到底是什么意思呢?
問(wèn)題描述
flaskweb開(kāi)發(fā)書(shū)中:
1 from flask import render_template, redirect, request, url_for, flash 2 from flask_login import login_user, logout_user, login_required,current_user 3 from . import auth 4 from .. import db 5 from ..models import User 6 from ..email import send_email 7 from .forms import LoginForm,RegistrationForm
上述.和..起到什么作用呢?tree是這樣的
├── app│?? ├── auth│?? │?? ├── forms.py│?? │?? ├── forms.pyc│?? │?? ├── __init__.py│?? │?? ├── __init__.pyc│?? │?? ├── views.py│?? │?? └── views.pyc│?? ├── email.py│?? ├── email.pyc│?? ├── __init__.py│?? ├── __init__.pyc│?? ├── main│?? │?? ├── errors.py│?? │?? ├── errors.pyc│?? │?? ├── forms.py│?? │?? ├── __init__.py│?? │?? ├── __init__.pyc│?? │?? ├── views.py│?? │?? └── views.pyc│?? ├── models.py│?? ├── models.pyc│?? ├── static│?? │?? └── favicon.ico│?? └── templates│?? ├── 404.html│?? ├── 500.html│?? ├── auth│?? │?? ├── email│?? │?? │?? ├── confirm.html│?? │?? │?? └── confirm.txt│?? │?? ├── login.html│?? │?? ├── register.html│?? │?? └── unconfirmed.html│?? ├── base.html│?? ├── index.html│?? └── mail│?? ├── new_user.html│?? └── new_user.txt├── config.py├── config.pyc├── LICENSE├── manage.py├── README.md├── requirements.txt└── tests ├── __init__.py ├── test_basics.py └── test_user_model.py
這個(gè)腳本在app/auth/下
問(wèn)題解答
回答1:.. 和 . 就是這個(gè)本目錄和上級(jí)目錄的意思,你一定會(huì)用 cd .. 吧
? ls -altotal 1660drwxr-xr-x+ 189 caimaoy staff 6426 4 11 10:07 .drwxr-xr-x 5 root admin 170 12 7 2015 ..
python 里面這樣寫也是一個(gè)意思,拿
from ..models import User
作為例子
models 相對(duì)于 auth 就是要先回到上層才能找到。
回答2:from . 是從當(dāng)前文件所在的目錄下尋找模塊文件,from .. 就是當(dāng)前文件所在的目錄上級(jí)目錄。
參考官方說(shuō)明在這:https://docs.python.org/2/tut...
回答3:from xx import xxximport xxpython使用這個(gè)導(dǎo)入模塊,模塊可以是函數(shù),類,集合。
這種方式主要是區(qū)別命名,如果調(diào)用的模塊函數(shù)名重復(fù),可以加以區(qū)分。
import xx 調(diào)用整個(gè)包。from xx import xxx 調(diào)用包里某個(gè)函數(shù)。
比如:我要書(shū)包 import bag我要書(shū)包里的書(shū) from bag import book
回答4:你想要的答案不在這里,認(rèn)真找本python基礎(chǔ)的書(shū)籍,關(guān)于模塊導(dǎo)入的內(nèi)容好好看看。
相關(guān)文章:
1. mysql - 在不允許改動(dòng)數(shù)據(jù)表的情況下,如何優(yōu)化以varchar格式存儲(chǔ)的時(shí)間的比較?2. css - chrome下a標(biāo)簽嵌套img 顯示會(huì)多個(gè)小箭頭?3. css3 - 純css實(shí)現(xiàn)點(diǎn)擊特效4. docker網(wǎng)絡(luò)端口映射,沒(méi)有方便點(diǎn)的操作方法么?5. java中返回一個(gè)對(duì)象,和輸出對(duì)像的值,意義在哪兒6. mysql 為什么主鍵 id 和 pid 都市索引, id > 10 走索引 time > 10 不走索引?7. vim - docker中新的ubuntu12.04鏡像,運(yùn)行vi提示,找不到命名.8. javascript - 有適合開(kāi)發(fā)手機(jī)端Html5網(wǎng)頁(yè)小游戲的前端框架嗎?9. javascript - Img.complete和img.onload判斷圖片加載完成有什么區(qū)別?10. 推薦好用mysql管理工具?for mac和pc
