简体   繁体   English

有没有办法从其他 IDE 中的 python 脚本在记事本 ++ 中打开文本文件?

[英]is there a way to open text file in notepad++ from python script in other some other IDE?

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我正在尝试从 python 脚本中打开一个文本文件特定行的文件我使用了这个

    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?这是在 notepad++ 中突出显示的第 1500 行打开 myfile.txt 但是当我尝试将-n(line-number)添加到subprocess.call([r"C:\Program Files\Notepad++\notepad++.exe", r"C"\location\myfile.txt"])它无法执行。有没有办法使用子进程或 os 模块在 python 脚本中执行此命令?

Yes, you actually can, by appending the additional arguments to the list of arguments that was already specified.是的,您实际上可以通过将附加的 arguments 附加到已指定的 arguments 列表中。 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"
])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM