Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个运行程序的 python 脚本,它生成几个 .exe 文件并将它们放在一个文件夹中。我想访问这些 exe 文件做进一步的测试,问题是这个文件夹名称不是静态的(它是动态的?),名称取决于操作系统、编译器、二进制类型(64/32 位),所以我可以不要对目录进行硬编码。
那么访问这样的文件夹最好的方法是什么?,我尝试查找此内容,但我不知道如何处理此问题。
只需将文件夹名称作为参数传递给您的 python 脚本:
python myscript.py FolderName
在myscript.py:
myscript.py
import sys print sys.argv[1]
sys.argv为您提供所有参数。
sys.argv
import platform
使用平台模块生成文件路径。
import os.path
使用os.path模块以一种很好的方式使用路径。