有没有办法执行文件仅知道子目录?
我有两个EXE文件 C:\ Users \ Bella \ Desktop \文件夹\ Fuctions
我想编写一个python脚本,可以从桌面\文件夹中打开两个脚本,问题是我想与人分享此脚本,我不知道他们的用户名称, 有没有一种方法可以执行文件,而仅知道它将在文件夹\ function中,因为我总是知道我的脚本会位于“文件夹”中,
import os
os.startfile(r"C:\Users\Bella\Desktop\Folder\Dist\fuctions\Test.exe")
os.startfile(r"C:\Users\Bella\Desktop\Folder\Dist\fuctions\Test2.exe")
显然是在与朋友共享时无法工作
I have two exe files located at
C:\Users\Bella\Desktop\Folder\fuctions
I want to write a python script that would open them both from Desktop\Folder, The issue is I want to share this script with people and I won't know the name of their User,
Is there a way to execute the files while only knowing it will be in Folder\functions since I will always know that my script will be located in "Folder"
import os
os.startfile(r"C:\Users\Bella\Desktop\Folder\Dist\fuctions\Test.exe")
os.startfile(r"C:\Users\Bella\Desktop\Folder\Dist\fuctions\Test2.exe")
obviously that wont work when shared to friends
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用评论中提到的相对路径或使用:
You can use relative path as mentioned in the comments or use:
使用os.environ.get(“用户名”)
它获得了用户的用户名。
或者,您可以使用os.getLogin()
upvote(如果有效):)
Use os.environ.get("USERNAME")
It gets the username of the user.
Or you can use os.getlogin()
Upvote if it works :)