Lazy loaded image
如何在Notepad++執行python程式碼
字数 604阅读时长≈ 2 分钟
2024-5-9
2024-9-24
type
status
date
slug
summary
tags
category
icon
password

前言

因為要把多個big5格式的文字檔批次轉換成UTF8格式。在找方法的過程中,找到其實可以用notepad++並搭配它的plugin python script批次完成此任務。以下解說如何安裝與操作的步驟。

安裝plugin PythonScript

在Notepadd++的menu bar選Plugins→ Plugins Admin…
notion image
搜尋PythonScript並安裝
notion image
按”是”,會安裝並自動重開Notepad++
notion image

新增並編輯python程式

開啟Plugins→Python Script→New Script

notion image
這時會開啟 C:\Users\[你的使用者名稱]\AppData\Roaming\Notepad++\plugins\config\PythonScript\scripts視窗,輸入你想要的檔名,在此用”HelloPython”為例。
在內容輸入

c

print "Hello Python"
C

打開console

notion image
這時就要出現下方的console視窗
notion image
 

執行程式

正規執行方式

notion image
執行完就會看到console出現Hello Python的字串
notion image
不過這個方法需要進入多層的選單,若在開發階段要經常執行程式碼就會較為麻煩。經過上網搜尋,找到以下另一種方法。

另一種較快速的執行方式

直接在命令列執行目前分頁的程式碼
在命令列輸入exec(editor1.getText())
如下圖所示
notion image
此方法可以直接執行目前編輯的視窗內的程式碼
 

Python Script的python版本

在console視窗的開頭就可以看到所使用的版本
notion image
 

如何替換Python版本

在原作者的說明檔 C:/Program Files/Notepad++/plugins/PythonScript/doc/usage.html#installation 中提到python的版本是在 notepad++的安裝目錄裡的plugins\PythonScript\的python??.dll,其中??就是所使用的版本C:\Program Files\Notepad++\plugins 。目前暫研究至此,尚未換python的版本,可能的做法是替換此檔案或安裝python。待網友們分享喔~
以下是檔案結構
 

c

Notepad++ (your main Notepad++ directory, probably under "C:\Program Files") + | +-- plugins \ | |-- PythonScript | \ | | | |-- PythonScript.dll | | | |-- python27.dll (maybe not necessary if you have a Python installation already, in which case it's probably in C:\windows ) | | | |-- lib | | \ | | |-- (*.py) lots of *.py files and subdirectories | | | |-- scripts | | \ | | |-- (machine-level scripts) | | | |-- doc | \ | |-- PythonScript | \ | |-- index.html (optional, if it's not there context-sensitive help will use the web) | | | |-- Config (this config directory can also be in %APPDATA%\Notepad++\plugins\config\) | \-- PythonScript \ |-- scripts \ |-- (user level scripts go here)
C
 
Reference:
上一篇
Rime 嘸蝦米輸入法方案
下一篇
如何修改NotionNext內文的文字大小

评论
Loading...