【问题标题】:is there a way to open text file in notepad++ from python script in other some other IDE?有没有办法从其他 IDE 中的 python 脚本打开 notepad++ 中的文本文件?
【发布时间】:2020-06-15 06:22:41
【问题描述】:

我正在尝试从在记事本++中用pycharm编写的python脚本打开一个文本文件我从以前的答案中发现我们可以使用子进程模块的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"]) 时,它无法执行。有什么方法可以使用 subprocess 或 os 模块在 python 脚本中执行此命令?

【问题讨论】:

    标签: python python-3.x notepad++


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2019-04-09
      • 2020-05-24
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      • 2020-11-17
      • 1970-01-01
      • 2019-01-30
      • 1970-01-01
      相关资源
      最近更新 更多