我目前正在为我的一个朋友开发一个使用数据库和所有类似东西的程序。现在,在对我需要做的事情进行基本规划时,我想如果我对自己的个人计算机的路径进行硬编码,我将如何让程序连接到正确的 MS Access 数据库?因为我将使用 pyinstaller 为他打包程序。
我是否需要以使用当前脚本路径的动态方式构建目录,然后对该路径进行一些字符串操作以获得正确的文件?IE
import os
file_path = os.path.realpath(__file__)
# Using prior knowledge knowing the file name length is 7
file_path = file_path[:-7]
#appending the path string to point to the database
file_path = file_path + "/databases/test.accdb"
还是该程序仍会以某种方式进入该数据库?