2014-11-25 2 views
0

파이썬 스크립트가 있습니다. 이건 내 셸 스크립트에 대한 나의 변환 일 뿐이야, 죄송합니다.이 언어에 대한 초보자입니다. 오류는 다음과 같습니다.SyntaxError : invalid syntax Python

File "chkrpm.py", line 19 
    if(rc != 0): 
    ^
SyntaxError: invalid syntax 

무엇이 잘못 되었나요? 이것은 내 쉘 스크립트입니다.

retval=0 
for i in $(cat /var/tools/tools/newrpms.txt) 
do 
     ls /var/patchbundle/rpms/ | grep $i 
     if [ $? != 0 ] 
     then 
       echo "$i NOT FOUND!" 
       retval=255 
     fi 
done 
exit $retval 

그리고 이것은 제 파이썬 변환입니다. 오류 측에만 집중하십시오.

import package, sys, os, subprocess 

path = '/var/tools/tools/newrpms.txt' 

newrpms = open(path, "w") 
fds = newrpms.readline() 
newrpms.close 


def checkrc(rc): 
       if(rc != 0): 
         sys.exit(rc) 
cmd = package.Errata() 
retval=0 


for i in newrpms: 
     rc = cmd.execute("ls /var/patchbundle/rpms/ | grep %newrpms ") 
       if(rc != 0): 
        cmd.logprint ("%s not found !" % i) 
        retval = 255 

checkrc(rc) 

내 코드에 무슨 문제가 있습니까? 그게 내 bash 스크립트처럼 들립니까? 내가 찾은 오류가 아래의 모든 제안을 따르도록했을 때

: 당신의 intendation이

루프에 보이는 잘못 때문에

File "chkrpm.py", line 19 
    echo("%s not found !" % i) 
    ^
SyntaxError: invalid syntax 
+0

참고 :'newrpms.close'는 아무 것도하지 않습니다. 파일을 닫으려면,'newrpms.close()':-) 함수를 호출해야합니다. – mgilson

+0

파일을 쓰기 모드로 열어 읽는 중입니다. 열기를'newrpms = open (path, "r")'로 변경하십시오. – nu11p01n73R

+0

'echo' 대신'print'를 사용하십시오. –

답변

0

귀하의 오류 메시지가`잘못된 구문을 '말 같은 :

for i in newrpms: 
     rc = cmd.execute("ls /var/patchbundle/rpms/ | grep %newrpms ") 
       if(rc != 0): 
        cmd.logprint ("%s not found !" % i) 
        retval = 255 

다음과 같이 표시되는 경우 :

for i in newrpms: 
    rc = cmd.execute("ls /var/patchbundle/rpms/ | grep %newrpms ") 
    if(rc != 0): 
     cmd.logprint ("%s not found !" % i) 
     etval = 255 
관련 문제