1. 程式人生 > >if、elif 條件判斷

if、elif 條件判斷

sys rfi elif 8.0 file shutil tar pro out

#!/usr/bin/python
#-*- codinig: UTF-8 -*-

from __future__ import print_function
import os, sys, stat
import shutil
import tarfile
import subprocess

output=subprocess.check_output(["hostname"], shell=True)
name=str(output.decode(utf8).strip()).strip(b)

f = open(/k8s/profile/etcd.service.py,r,encoding=
utf-8) f_new = open(/k8s/profile/etcd.service,w,encoding=utf-8) for line in f: if "NODE_NAME" in line: line = line.replace(NODE_NAME,name) elif "NODE_IP" in line: line = line.replace(NODE_IP,192.168.0.91) f_new.write(line) print("替換完成") f.close() f_new.close()

if、elif 條件判斷