python - from ..xxxx import xxxx到底是什么意思呢?
問題描述
flaskweb開發(fā)書中:
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/下
問題解答
回答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í)目錄。
參考官方說明在這: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ù)。
比如:我要書包 import bag我要書包里的書 from bag import book
回答4:你想要的答案不在這里,認(rèn)真找本python基礎(chǔ)的書籍,關(guān)于模塊導(dǎo)入的內(nèi)容好好看看。
相關(guān)文章:
1. 為什么python中實(shí)例檢查推薦使用isinstance而不是type?2. python - (初學(xué)者)代碼運(yùn)行不起來,求指導(dǎo),謝謝!3. 老師您的微信號(hào)是多少?4. nginx - pip install python庫報(bào)錯(cuò)5. mysql如何添加索引的時(shí)候指定索引方式6. python - django orm 過濾日期為當(dāng)天日期的數(shù)據(jù)7. mysql - 5千萬文章,怎么做相關(guān)文章?8. python - 如何判斷字符串為企業(yè)注冊(cè)名稱9. mysql里的大表用mycat做水平拆分,是不是要先手動(dòng)分好,再配置mycat10. window下mysql中文亂碼怎么解決??
