开发者

"Unexpected indent" when trying to call os.system

Pretty simple question (probably) but I guess since im new to python im not super sure about how os.system works.

Basically I have a for loop (thanks to some help from SO) that goes through all my directories and runs a shell script (like 120 something different shell scripts).

import os

root = '/foo/'

for directory, subdirectories, files in os.walk(root):
  for file in files:
     if os.path.splitext(file)[-1].lower() == '.sh':

Basically what I want to do is this (if it were in unix) (ignore the IP address but there will be an IP address each time) sh run.sh 157.111.22.134 >> logfile.txt THEN sh remove.sh 157.111.22.134

I tried something like this

#!/usr/bin/env python

import os

root = "~/users/me"
ip = '157.111.22.134'
for directory, subdirectories, files in os.walk(root):
  for file in file开发者_如何学Gos:
     if os.path.splitext(file)[-1].lower() == '.sh':
       os.system('sh ' + os.path.join(directory, file) + ' ' + ip + '>>' ' log.txt')
       os.system('sh ' + 'remove.sh ' + ip)

but it complained about the second os.system (saying "unexpected indent")

and im not even sure if I have it right? ideas?


You're mixing up your indentation (spaces vs. tabs). Use python -tt to verify.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜