推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
smdbh
V2EX  ›  Python

sqlite 的文件路径怎么写

  •  
  •   smdbh · Jun 12, 2018 · 3035 views
    This topic created in 2961 days ago, the information mentioned may be changed or developed.
    比如有个自己写的各种 sql 查询的 a.py ,使用同级文件夹内的 a.sqlite 作为数据库文件。打开数据库直接用 a.sqlite 作为输入,发现上级目录调用 a.py 时,a.sqlite 的路径不对了,是调用目录下的 a.sqlite 了。 如果这个 sql 模块要适用不用调用者的目录结构,该怎么访问本级目录呢?
    2 replies    2018-06-12 19:37:50 +08:00
    smdbh
        1
    smdbh  
    OP
       Jun 12, 2018
    好像可以用 realpath
    ThirdFlame
        2
    ThirdFlame  
       Jun 12, 2018   ❤️ 1
    请使用
    ```
    import os
    BASE_PATH = os.path.abspath(os.path.dirname(__file__))
    sqlite_filename=os.path.join(BASE_PATH,'a.sqlite')
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5640 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 01:39 · PVG 09:39 · LAX 18:39 · JFK 21:39
    ♥ Do have faith in what you're doing.