0

I get this error while trying to open a txt. file. Please tell how to fix it .

code: subprocess.Popen("/home/yash/Documents/ct.txt") time.sleep(1) error: Traceback (most recent call last): File "/home/yash/Documents/final_downloader22.py", line 5, in <module> subprocess.Popen("/home/yash/Documents/ct.txt") File "/usr/lib/python2.7/subprocess.py", line 679, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child raise child_exception OSError: [Errno 13] Permission denied 

2 Answers 2

1

Text files are normally not executable. What do you mean with "open" here?

  1. This could mean "open it so that I can use it in the program".

    This works with file_object = open('/home/yash/Documents/ct.txt', 'r') and then using that file_object.

  2. This as well could mean "let the file type's associated application open the file so that the user can edit it".

    In this case, you would have to find out what the associated application is. How you do this is dependent on the OS you use as well as the window manager/desktop environment. It cannot be answered in a few short sentences.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for reply ,i'm running linux and i want to open it with gedit to edit it any further help possible .
@user1779646 Then call gedit and tell it to load the txt file: subprocess.Popen(['gedit', "/home/yash/Documents/ct.txt"]).
1

You could use webbrowser module to open a text file for editing in a portable manner in a script:

import webbrowser webbrowser.open("/home/yash/Documents/ct.txt") 

From a command-line:

$ python -mwebbrowser "/home/yash/Documents/ct.txt" 

See also patches for "Add shutil.open" Python issue.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.