简体   繁体   中英

How to run a .txt with an .exe using python? (“dragging” .txt into .exe)

Me and my friend are trying to make a small program and we need to be able to do the same as if you would be dragging the.txt into the.exe, but with python.

The.exe is a converter which we need in order to read the.txt file. We already can choose the file, but I couldn't find anything about how to run 2 files together.

I hope someone can help!

When you drag a file into an executable, its pathname is passed as the first command-line argument (see sys.argv ).

Depending on how your Windows environment is configured, the .py file type may already be marked in a way that lets you drag other files onto them in File Explorer, so you'll end up with the Python interpreter running the script with the dragged file's pathname in sys.argv .

If that's not the case, you can use eg https://www.pyinstaller.org/ or https://github.com/indygreg/PyOxidizer or https://www.py2exe.org/ to make an.exe out of your Python script with which the drag-and-drop functionality will certainly work.

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