-5

我是 python 新手。我对功能有一点怀疑split()。我想在字符串“成功”之后拆分行。我如何使用拆分方法来做到这一点。

File system activity

Opened files...

C:\27e7a559f98a0fbe14ba3a3cd8b4f3c2400c6581134a97c382e9d465b807fa87 (successful)C:\Documents and Settings\<USER>\Local Settings\Application Data\tac.exe (successful)C:\Documents and Settings\<USER>\Local Settings\Application Data\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)C:\Documents and Settings\All Users\Application Data\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)C:\DOCUME~1\<USER>~1\LOCALS~1\Temp\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)C:\Documents and Settings\<USER>\Templates\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)\\.\PIPE\lsarpc (successful)C:\WINDOWS\system32\wscui.cpl (successful)C:\WINDOWS\system32\xpsp2res.dll (successful)C:\WINDOWS\system32\inetcpl.cpl (successful)\\.\Ip (successful)C:\WINDOWS\system32\drivers\etc\hosts (successful)C:\WINDOWS\system32\rsaenh.dll (successful)\\.\WMIDataDevice (successful)C:\WINDOWS\Registration\R000000000007.clb (successful)C:\WINDOWS\WindowsShell.manifest (successful)C:\Documents and Settings\<USER>\Local Settings\Application Data\GDIPFONTCACHEV1.DAT (successful)C:\WINDOWS\FONTS\TREBUC.TTF (successful)C:\WINDOWS\FONTS\TREBUCBD.TTF (successful)C:\WINDOWS\FONTS\TREBUCIT.TTF (successful)C:\WINDOWS\FONTS\TREBUCBI.TTF (successful)C:\WINDOWS\system32\shdocvw.dll (successful)C:\WINDOWS\system32\stdole2.tlb (successful)C:\WINDOWS\FONTS\TAHOMA.TTF (successful)C:\WINDOWS\FONTS\TAHOMABD.TTF (successful)

输出应该是这样的

File system activity

Opened files...

C:\27e7a559f98a0fbe14ba3a3cd8b4f3c2400c6581134a97c382e9d465b807fa87 (successful)

C:\Documents and Settings\<USER>\Local Settings\Application Data\tac.exe (successful)

提前致谢

4

2 回答 2

2
In [31]: output = r"C:\27e7a559f98a0fbe14ba3a3cd8b4f3c2400c6581134a97c382e9d465b807fa87 (successful)C:\Documents and Settings\<USER>\Local Settings\Application Data\tac.exe (successful)C:\Documents and Settings\<USER>\Local Settings\Application Data\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)C:\Documents and Settings\All Users\Application Data\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)C:\DOCUME~1\<USER>~1\LOCALS~1\Temp\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)C:\Documents and Settings\<USER>\Templates\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)\\.\PIPE\lsarpc (successful)C:\WINDOWS\system32\wscui.cpl (successful)C:\WINDOWS\system32\xpsp2res.dll (successful)C:\WINDOWS\system32\inetcpl.cpl (successful)\\.\Ip (successful)C:\WINDOWS\system32\drivers\etc\hosts (successful)C:\WINDOWS\system32\rsaenh.dll (successful)\\.\WMIDataDevice (successful)C:\WINDOWS\Registration\R000000000007.clb (successful)C:\WINDOWS\WindowsShell.manifest (successful)C:\Documents and Settings\<USER>\Local Settings\Application Data\GDIPFONTCACHEV1.DAT (successful)C:\WINDOWS\FONTS\TREBUC.TTF (successful)C:\WINDOWS\FONTS\TREBUCBD.TTF (successful)C:\WINDOWS\FONTS\TREBUCIT.TTF (successful)C:\WINDOWS\FONTS\TREBUCBI.TTF (successful)C:\WINDOWS\system32\shdocvw.dll (successful)C:\WINDOWS\system32\stdole2.tlb (successful)C:\WINDOWS\FONTS\TAHOMA.TTF (successful)C:\WINDOWS\FONTS\TAHOMABD.TTF (successful)"

In [32]: while output:
   ....:     left, mid, output = output.partition("(successful)")
   ....:     print left+mid
   ....:     
C:\27e7a559f98a0fbe14ba3a3cd8b4f3c2400c6581134a97c382e9d465b807fa87 (successful)
C:\Documents and Settings\<USER>\Local Settings\Application Data\tac.exe (successful)
C:\Documents and Settings\<USER>\Local Settings\Application Data\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)
C:\Documents and Settings\All Users\Application Data\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)
C:\DOCUME~1\<USER>~1\LOCALS~1\Temp\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)
C:\Documents and Settings\<USER>\Templates\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)
\\.\PIPE\lsarpc (successful)
C:\WINDOWS\system32\wscui.cpl (successful)
C:\WINDOWS\system32\xpsp2res.dll (successful)
C:\WINDOWS\system32\inetcpl.cpl (successful)
\\.\Ip (successful)
C:\WINDOWS\system32\drivers\etc\hosts (successful)
C:\WINDOWS\system32\rsaenh.dll (successful)
\\.\WMIDataDevice (successful)
C:\WINDOWS\Registration\R000000000007.clb (successful)
C:\WINDOWS\WindowsShell.manifest (successful)
C:\Documents and Settings\<USER>\Local Settings\Application Data\GDIPFONTCACHEV1.DAT (successful)
C:\WINDOWS\FONTS\TREBUC.TTF (successful)
C:\WINDOWS\FONTS\TREBUCBD.TTF (successful)
C:\WINDOWS\FONTS\TREBUCIT.TTF (successful)
C:\WINDOWS\FONTS\TREBUCBI.TTF (successful)
C:\WINDOWS\system32\shdocvw.dll (successful)
C:\WINDOWS\system32\stdole2.tlb (successful)
C:\WINDOWS\FONTS\TAHOMA.TTF (successful)
C:\WINDOWS\FONTS\TAHOMABD.TTF (successful)
于 2013-02-01T07:13:03.083 回答
0
output = r"C:\27e7a559f98a0fbe14ba3a3cd8b4f3c2400c6581134a97c382e9d465b807fa87 (successful)C:\Documents and Settings\<USER>\Local Settings\Application Data\tac.exe (successful)C:\Documents and Settings\<USER>\Local Settings\Application Data\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)C:\Documents and Settings\All Users\Application Data\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)C:\DOCUME~1\<USER>~1\LOCALS~1\Temp\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)C:\Documents and Settings\<USER>\Templates\1pb78m8n6he1l1565b3k36w7o7of8ksb88y53s63tpqg0vl (successful)\\.\PIPE\lsarpc (successful)C:\WINDOWS\system32\wscui.cpl (successful)C:\WINDOWS\system32\xpsp2res.dll (successful)C:\WINDOWS\system32\inetcpl.cpl (successful)\\.\Ip (successful)C:\WINDOWS\system32\drivers\etc\hosts (successful)C:\WINDOWS\system32\rsaenh.dll (successful)\\.\WMIDataDevice (successful)C:\WINDOWS\Registration\R000000000007.clb (successful)C:\WINDOWS\WindowsShell.manifest (successful)C:\Documents and Settings\<USER>\Local Settings\Application Data\GDIPFONTCACHEV1.DAT (successful)C:\WINDOWS\FONTS\TREBUC.TTF (successful)C:\WINDOWS\FONTS\TREBUCBD.TTF (successful)C:\WINDOWS\FONTS\TREBUCIT.TTF (successful)C:\WINDOWS\FONTS\TREBUCBI.TTF (successful)C:\WINDOWS\system32\shdocvw.dll (successful)C:\WINDOWS\system32\stdole2.tlb (successful)C:\WINDOWS\FONTS\TAHOMA.TTF (successful)C:\WINDOWS\FONTS\TAHOMABD.TTF (successful)"

sep='(successful)'
ls=output.split(sep)
for i in ls[:-1]:
    print i+sep
print ls[-1]
于 2013-02-01T07:30:06.620 回答