“打开方式……"Windows 上的文件,带有 python 应用程序 [英] "Open with..." a file on Windows, with a python application

查看:28
本文介绍了“打开方式……"Windows 上的文件,带有 python 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚当用户右键单击文件并选择打开方式"时如何让 python 程序打开文件.例如,我希望用户能够右键单击文本文件并选择我的程序,以便我的程序可以处理该文本文件.文本文件的名称是否以某种方式传递到我的程序中?谢谢.

I am trying to figure out how to make a python program open a file when a user right clicks on the file and selects "Open With". For example, I want a user to be able right click on a text file and to select my program so that my program can process the text file. Is the name of the text file passed into my program someway? Thanks.

推荐答案

我的方法是使用包含 python someprogram.py %1 的重定向 .bat 文件.%1 将文件路径传递到可以使用
访问的 python 脚本中from sys import argvargv[1]

My approach is to use a redirect .bat file containing python someprogram.py %1. The %1 passes the file path into the python script which can be accessed with
from sys import argv argv[1]

这篇关于“打开方式……"Windows 上的文件,带有 python 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆