I am trying to open a text file from python script written in pycharm in notepad++ I found from the previous answers that we can use the command in the python from the subprocess module to open the specific file but I want to open the notepad++ to open a file at specific line I used this
import subprocess
subprocess.call([r"C:\Program Files\Notepad++\notepad++.exe", r"C:\location\myfile.txt"])
but it is opening without any specific focus but i know the following command prompt option to open the my text file at specific line using below command line command
start notepad++ "C:\location\myfile.txt" -n1500
this is opening the myfile.txt at line number 1500 highlighted in notepad++ but when I am trying to add the -n(line-number)
to the subprocess.call([r"C:\Program Files\Notepad++\notepad++.exe", r"C"\location\myfile.txt"])
the it is not able to execute. Is there any way to execute this command in python script using subprocess or os module?
Yes, you actually can, by appending the additional arguments to the list of arguments that was already specified. The following should achieve the command launched from the command line:
subprocess.call([
r"C:\Program Files\Notepad++\notepad++.exe", r"C:\location\myfile.txt",
"-n1500"
])