-5

私はPythonを初めて使用します。機能に少し疑問がありsplit()ます。文字列「successful」の後に行を分割したい。分割方法を使用してそれを行うにはどうすればよいですか。

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 に答える