[英]How to modify a filepath in Python code so that it works on other computers?
I am writing a simple code that runs a batch file and opening of an excel sheet to store some data. 我正在编写一个简单的代码,该代码运行批处理文件并打开excel工作表以存储一些数据。 I have given the location of the file on my computer. 我已经在计算机上指定了文件的位置。 I want to use "pyinstaller" to create an executable so that I can run in other computers as well. 我想使用“ pyinstaller”创建可执行文件,以便我也可以在其他计算机上运行。 Where should I put the *.xlsx and *.bat file in the new computer so that it works, and also should I change the file path in my program? 我应该将* .xlsx和* .bat文件放在新计算机的什么位置,以便它可以工作,还应该在程序中更改文件路径? If so how? 如果可以,怎么办?
filepath = r"F:\project\printingdatabase.xlsx"
wb = load_workbook(filepath)
subprocess.call(r"F:\project\batfile\tester.bat")
# This gets you the dir of the current script in an os-independent way, for example
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# This appends a subdir "sub-dir" to the base path, in an os-independent way
os.path.join(BASE_DIR, 'sub-dir')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.