5
나는 처리하고 싶은 데이터 세트를 가지고있다. 리눅스에서 "awk"명령을 실행하기 위해 파이썬 코드를 실행하려고했습니다. 내가 어떻게 다른 논증이나 기능을 시도해도 상관 없습니다. 모두 작동하지 않았습니다.파이썬 코드로 awk 명령을 실행하는 방법
내가 시도한 두 가지 다른 방법이 있지만 모두 작동하지 않았습니다. 나도 몰라 왜
1)
#!/usr/bin/env python
import subprocess as sp
cmd = "awk, '{print $2 '\t' $4 '\t' $5 '\t' $6}', B3LYPD.txt"
args = cmd.split(',')
p = sp.Popen(args, stdin = sp.PIPE, stdout = sp.PIPE, stderr = sp.PIPE)
2)
#!/usr/bin/env python
import subprocess as sp
cmd = "awk, '{print $2 '\t' $4 '\t' $5 '\t' $6}'"
args = cmd.split(',')
p = sp.Popen(args, stdin = sp.PIPE, stdout = sp.PIPE, stderr = sp.PIPE)
c = p.communicate('B3LYPD.txt')
print c
'str.split'이 아닌'shlex.split'을 사용하십시오. –
이미 파이썬으로 프로그래밍 중이라면'awk'를 호출해야합니까? 파이썬은 아마'awk'에서 필요한 모든 것을 할 수 있습니다. –
문자열리스트가 필요하다면'c = "this, that, other,"; args = cmd.split (',')'이면, args = [ "this", "that", "other"]'를 사용하고 split 명령을 건너 뛸 수 있습니다. –