python - from ..xxxx import xxxx到底是什么意思呢?

查看:639
本文介绍了python - from ..xxxx import xxxx到底是什么意思呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

flaskweb开发书中:

  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

这个脚本在app/auth/下

解决方案

.. 和 . 就是这个本目录和上级目录的意思,你一定会用 cd ..

❯ ls -al
total 1660
drwxr-xr-x+ 189 caimaoy staff   6426  4 11 10:07  .
drwxr-xr-x    5 root    admin    170 12  7  2015  ..

python 里面这样写也是一个意思,拿

from ..models import User

作为例子

models 相对于 auth 就是要先回到上层才能找到。

这篇关于python - from ..xxxx import xxxx到底是什么意思呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆