D
D
Daniil Shevkunov2021-07-22 22:30:12
Python
Daniil Shevkunov, 2021-07-22 22:30:12

How can I make the script get the path to the file when dragging a file onto the script?

Conventionally, there is a main.py file and next to it in the same test.txt folder.
I drag test.txt onto main.py and it runs with the path to the test.txt file.

I saw a similar topic, but the exe file was compiled there.

Tried to write:

import sys
print(sys.argv[1])
input()

But nothing happened, and I concluded that this would not work.

Is it possible to do something like this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Shevkunov, 2021-07-23
@danila763

I found a solution, the error was that I opened the file using the interpreter:
C:\Python\Python39\python.exe
And I had to open it with the python launcher -a
C:\Windows\py.exe
Thanks Gennady S for help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question