我有以下Python代码
import psutil
import re
_list = psutil.get_pid_list()
for i in _list:
if i > 0:
_process_path = psutil.Process(i).exe
_match = re.search('\/Applications\/.*\.app\/',_process_path)
if _match:
print _process_path
它是有效的,下面是它返回的示例:
/Applications/RegExr.app/Contents/MacOS/RegExr
/Applications/Google Chrome.app/Contents/Versions/24.0.1312.57/Google Chrome Helper.app/Contents/MacOS/Google Chrome Helper
/Applications/TextWrangler.app/Contents/Helpers/Crash Reporter.app/Contents/Helpers/crash-catcher
/Applications/TextWrangler.app/Contents/MacOS/TextWrangler
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome
/Applications/Utilities/Activity Monitor.app/Contents/MacOS/Activity Monitor
/Applications/AppCleaner.app/Contents/Library/LoginItems/AppCleaner Helper.app/Contents/MacOS/AppCleaner Helper
/Applications/Transmit.app/Contents/MacOS/TransmitMenu.app/Contents/MacOS/TransmitMenu
/Applications/Twitter.app/Contents/MacOS/Twitter
/Applications/ScreenFlow.app/Contents/MacOS/ScreenFlowHelper.app/Contents/MacOS/ScreenFlowHelper
如何使它只返回这个?你知道吗
/Applications/RegExr.app
/Applications/Google Chrome.app
/Applications/TextWrangler.app/Contents/Helpers/Crash Reporter.app
/Applications/TextWrangler.app
/Applications/Google Chrome.app
/Applications/Utilities/Activity Monitor.app
/Applications/AppCleaner.app
/Applications/Transmit.app
/Applications/Twitter.app
/Applications/ScreenFlow.app
而是使用^{} method 打印匹配的组:
您的
_match
对象可以将匹配的文本返回为_match.group(0)
。你知道吗相关问题 更多 >
编程相关推荐