简体   繁体   中英

Executing a file using a Python script

I don't have a clue on where to look for a solution to this. Basically i want to make a file that can be "opened with" a python script. The directory of the opened file will be stored as a variable in the script. Here's what I mean by "Open With":

Sorry if I'm not too good at describing this.

There might be a more direct way, but one approach could be to write a simple batch file that invokes the Python interpreter with your script:

main.bat

@echo off
python main.py %1

Add absolute or relative paths if necessary.

Within main.py , the name of the file should then be available as sys.argv[1] .

If I'm not misunderstanding, what you want is your argv[1] be 'C:.PythonCode2\runfileswith\test.phktest'.

I did some test on my Windows 10, simply drag the .phktest file onto the main.py will let sys.argv[1] be the full path of that file!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM