Nov-23-2018, 10:36 AM
Hi All,
Expectation is to get a file as "pre.hostname" if doesn't exist in current directory but i am getting "pre.hostname?" instead.
Can someone correct me?
I am using python-3.3.1 on RHEL 7 OS
Expectation is to get a file as "pre.hostname" if doesn't exist in current directory but i am getting "pre.hostname?" instead.
Can someone correct me?
I am using python-3.3.1 on RHEL 7 OS
import subprocess
from subprocess import check_output
import os
import os.path
cur_dir = os.getcwd()
#pwd = check_output("pwd", shell=True).decode()
hostname = check_output("hostname", shell=True).decode()
pre = ("/pre.")
post = ("/post.")
print ()
print ("Current Directory :", cur_dir)
fname = (cur_dir+pre+hostname)
print ("Checking the existence of File", fname)
if os.path.isfile(fname):
print ("File Exists")
else:
print ("File Doesn't exist; Creating a new one")
file1 = open(fname, "w").close()
