Is it possible to use try
to achieve that either creating a new file with a header or appending if the file exists.
Secondly, could I add two statements under except
clause.
Hname = os.uname()[1].split(".")[0]
Cdate = datetime.now().strftime("%Y%m%d")
# .....
MPSTAT = '/home/mongod/monitor/rpt/'+Hname+'/mpstat.'+Cdate
try:
f_mpstat = open(MPSTAT,'r')
except FileNotFoundError:
f_mpstat = open(MPSTAT,'w')
f_mpstat.write("Start time => {0} interval => {1:4d} count => {2:4d} \n".format(Ctime, Interval, Count))
f_mpstat = open(MPSTAT,'a')