-2

I'm trying to get the path of a file in python which I run with an exe file. Here is an Image which descibes the problem ("Mit runWithJar.exe öffnen" means "Open with runWithJar.exe"): Image

In the window of my console based application I get this output: Image with the console output

How can I get the second path in my python script?

I am using Python 3.9 and Windows 10

fthomson
  • 773
  • 3
  • 9

1 Answers1

0

Do you have the original .py file that was the base for the .exe? Because this should be rather simple to do with a few lines of Python code:

import sys
 
drop_file = sys.argv[1]
print(f"You dropped {drop_file}")
with open(drop_file) as f:
    print(f.read())
input("Press <Enter> to exit")

Adopted from here. The person who posted this replied that it also worked with .exe build with PyInstaller. It might be required to create a simple .bat file - it depends on your system settings. You might also want to check this for more information on the drag-and-drop and Python.

tpwo
  • 484
  • 3
  • 12