如何通过.EXE Python程序打开哪个文件

发布于 2025-01-17 16:12:39 字数 158 浏览 1 评论 0原文

因此,我正在尝试创建一个程序,该程序能够读取自己的类型的文件类型,

以想象一个名为 hello.world 的文件

,并且您有一个.exe程序,您可以使用该程序。

该程序是我的Python文件,那么使用该.EXE打开哪个文件的实际方式是什么?

So I am trying to create a program that would be able to read its own types of files

Imagine there is a file called hello.world

And you have a .exe program that you can open this file with.

This program is my python file, so what is actually the way of getting which file was opened with that .exe?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑脸一如从前 2025-01-24 16:12:39

经过评论中的小讨论:

可以使用 sys.argv 来获取文件路径:
从 python 中的命令行参数获取文件路径

filename = sys.argv[1]
print(filename)

if os.path.exists(fn):
    print os.path.basename(fn)
    # file exists

After a small discussion in the comments:

it is possible to use sys.argv to get the file path:
getting file path from command line argument in python

filename = sys.argv[1]
print(filename)

if os.path.exists(fn):
    print os.path.basename(fn)
    # file exists
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文