0
Hello. I’m creating a small Python notepad and wanted to know how I open a file. txt using it from 2 clicks in Windows Explorer?
0
Hello. I’m creating a small Python notepad and wanted to know how I open a file. txt using it from 2 clicks in Windows Explorer?
0
In the context menu go to Open With->Python and use a script like this:
file = open("text1.txt", "r")
print(file.read())
input("Press Enter to quit: ")
0
You can create a file . bat calls python and associate the . txt files to your program . bat.
bat file.
python programa.py %1
This way is passed the name of the file you opened is passed as argument.
To get the file name just use argv
import sys
sys.argv[0] # Sempre o caminho do programa
sys.argv[1] # O primeiro argumento, no seu caso o arquivo aberto.
I hope I’ve helped.
@gigafleet
Thank you very much!
Browser other questions tagged python python-3.x
You are not signed in. Login or sign up in order to post.
Thanks for trying to help me, but, the script needs to open along with the file while making two clicks on windows explorer, type, files. docx, when giving 2 clicks on it the word opens showing the document. In your example, the file to be opened must be predetermined
– Vandiscleisson N.
With an . bat file it is possible to use drag and drop to open a file dynamically.
– tomasantunes