Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing a file using a Python script

Tags:

python

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.

like image 816
Expliked Avatar asked May 11 '26 06:05

Expliked


1 Answers

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].

like image 62
Thomas Avatar answered May 12 '26 19:05

Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!