小编sha*_*ash的帖子

检查进程是否在Python中运行(在Linux/Unix中)

我试图找出进程是否基于进程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.

有什么建议?谢谢你的帮助.

python linux

37
推荐指数
6
解决办法
8万
查看次数

基于字符串拆分文件

我试图将一个大文件拆分成单独的条目.每个条目以字符"//"结尾.所以当我尝试使用时

#!/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),因此它也在那里分裂,最终我没有得到我想要的结果.我尝试使用正则表达式,但无法弄明白.

python

3
推荐指数
1
解决办法
5861
查看次数

在python中使用正则表达式匹配一行中的单词列表

我正在寻找一个表达式来将字符串与诸如["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)

python

0
推荐指数
1
解决办法
4486
查看次数

标签 统计

python ×3

linux ×1