V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2018-06-12 15:44:20 +08:00 · 2281 次点击
    这是一个创建于 2116 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如有个自己写的各种 sql 查询的 a.py ,使用同级文件夹内的 a.sqlite 作为数据库文件。打开数据库直接用 a.sqlite 作为输入,发现上级目录调用 a.py 时,a.sqlite 的路径不对了,是调用目录下的 a.sqlite 了。 如果这个 sql 模块要适用不用调用者的目录结构,该怎么访问本级目录呢?
    2 条回复    2018-06-12 19:37:50 +08:00
    smdbh
        1
    smdbh  
    OP
       2018-06-12 15:49:07 +08:00
    好像可以用 realpath
    ThirdFlame
        2
    ThirdFlame  
       2018-06-12 19:37:50 +08:00   ❤️ 1
    请使用
    ```
    import os
    BASE_PATH = os.path.abspath(os.path.dirname(__file__))
    sqlite_filename=os.path.join(BASE_PATH,'a.sqlite')
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1335 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 17:43 · PVG 01:43 · LAX 10:43 · JFK 13:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.