python模块导入的问题

 joanV- 发布于 2022-11-05 07:16

看python requests的源码,其中有如下代码

from . import utils其中的点是什么意思,直接在命令行上执行是报错的

[yaxin@cube2x requests]$ls
adapters.py  auth.py     certs.py   cookies.py     hooks.py     models.py  sessions.py      structures.py
api.py       cacert.pem  compat.py  exceptions.py  __init__.py  packages   status_codes.py  utils.py
[yaxin@cube2x requests]$python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from . import utils
Traceback (most recent call last):
  File "", line 1, in 
ValueError: Attempted relative import in non-package
>>> 
3 个回答
  • . 是路径啦!

    2022-11-09 03:39 回答
  • . 相对当前工作目录
    如果不在当前目录环境,则将.替换为完整的模块路径

    2022-11-09 03:40 回答
  • . 表示当前的工作目录

    在python中 应该是默认引用 ____init____.py

    2022-11-09 03:52 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有