我试图找出进程是否基于进程ID运行.根据论坛上的帖子之一,代码如下.我不能考虑进程名称,因为有多个进程使用相同的名称运行.
def findProcess( processId ):
ps= subprocess.Popen("ps -ef | grep "+processId, shell=True, stdout=subprocess.PIPE)
output = ps.stdout.read()
ps.stdout.close()
ps.wait()
return output
def isProcessRunning( processId):
output = findProcess( processId )
if re.search(processId, output) is None:
return true
else:
return False
Run Code Online (Sandbox Code Playgroud)
输出:
1111 72312 72311 0 0:00.00 ttys000 0:00.00 /bin/sh -c ps -ef | grep 71676
1111 72314 72312 0 0:00.00 ttys000 0:00.00 grep 71676
Run Code Online (Sandbox Code Playgroud)
它总是返回true,因为它可以在输出字符串中找到进程id.
有什么建议?谢谢你的帮助.
我试图将一个大文件拆分成单独的条目.每个条目以字符"//"结尾.所以当我尝试使用时
#!/usr/bin/python
import sys,os
uniprotFile=open("UNIPROT-data.txt") #read original alignment file
uniprotFileContent=uniprotFile.read()
uniprotFileList=uniprotFileContent.split("//")
for items in uniprotFileList:
seqInfoFile=open('%s.dat'%items[5:14],'w')
seqInfoFile.write(str(items))
Run Code Online (Sandbox Code Playgroud)
但我意识到还有另一个字符串"//"(http://www.uniprot.org/terms),因此它也在那里分裂,最终我没有得到我想要的结果.我尝试使用正则表达式,但无法弄明白.
我正在寻找一个表达式来将字符串与诸如["xxx", "yyy", "zzz"]. 字符串需要包含所有三个单词,但它们的顺序不必相同。
例如,应匹配以下字符串:
'"yyy" string of words and than “zzz" string of words “xxx"'
Run Code Online (Sandbox Code Playgroud)
或者
'string of words “yyy””xxx””zzz” string of words'
Run Code Online (Sandbox Code Playgroud)