Python Forum
How to write a code to open and read text file by clicking on the "text file"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to write a code to open and read text file by clicking on the "text file"
#2
You want to associate text files extension with a Python program?
This is possible, but I think it's not a good idea to open all text files generally with Python.

  1. Associate the extension .txt to 'py C:\windows\your_script.py'
  2. Clicking now on a .txt file should call following: 'py C:\windows\your_script.py filename.txt'

Then you read with sys.argv[1] the first argument from the commandline.
sys.argv[0] is the python-script.

Then you can do what you want with the path.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: How to write a code to open and read text file by clicking on the "text file" - by DeaD_EyE - Jul-03-2018, 10:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 505 4 hours ago
Last Post: AdamHensley
  Regex to catch what user has put in text box robertkwild 10 429 Jun-13-2024, 05:44 PM
Last Post: deanhystad
  Reading an ASCII text file and parsing data... oradba4u 2 216 Jun-08-2024, 12:41 AM
Last Post: oradba4u
  Delete file with read-only permission, but write permission to parent folder cubei 6 22,374 Jun-01-2024, 07:22 AM
Last Post: Eleanorreo
  speed up getting embedding from bert model for large set of text veda 7 437 May-27-2024, 08:28 AM
Last Post: Pedroski55
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 405 May-03-2024, 07:23 AM
Last Post: Pedroski55
  UART write binary code trix 3 477 Apr-28-2024, 04:57 PM
Last Post: deanhystad
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 1,444 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  What does .flush do? How can I change this to write to the file? Pedroski55 3 418 Apr-22-2024, 01:15 PM
Last Post: snippsat
Brick Number stored as text with openpyxl CAD79 2 746 Apr-17-2024, 10:17 AM
Last Post: CAD79

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020