簡體   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