繁体   English   中英

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

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

我正在尝试从 python 脚本中打开一个文本文件特定行的文件我使用了这个

    import subprocess
    subprocess.call([r"C:\Program Files\Notepad++\notepad++.exe", r"C:\location\myfile.txt"])

但它在没有任何特定焦点的情况下打开,但我知道以下命令提示符选项可使用以下命令行命令在特定行打开我的文本文件

start notepad++ "C:\location\myfile.txt" -n1500

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

是的,您实际上可以通过将附加的 arguments 附加到已指定的 arguments 列表中。 下面应该实现从命令行启动的命令:

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