This topic created in 3092 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
 |
|
好像可以用 realpath
|
 |
|
请使用 ``` import os BASE_PATH = os.path.abspath(os.path.dirname(__file__)) sqlite_filename=os.path.join(BASE_PATH,'a.sqlite') ```
|