I am a beginner in python . why the variable "env" being used while opening the file and other places in the following code . From the tutorials i have seen file opening formats were always like with open(filename) as f , but here a variable name is being used. Please explain .
def main():
global debug, testing,env, mode
newID=0
rv=[]
name=''
if "debug" in sys.argv:
debug = True
if "testing" in sys.argv:
testing = True
if debug:
print(sys.argv)
if "copyAccountProfile" in sys.argv:
mode = 'copyAccountProfile'
envProfile = sys.argv[1]
if debug:
print(envProfile)
with open(envProfile) as f_in:
lineList = list(line for line in (l.strip() for l in f_in) if line)
# ff = open(envProfile)
# lineList = [line for line in ff.readlines() if line.strip()]
for line in lineList:
if line.startswith('#'):
continue
[nm, v]=line.strip().split('=')
env[nm.strip()]=v.strip()
if debug:
print(env)
with open(env['accountProfile']) as f_in:
accountList = list(line for line in (l.strip() for l in f_in) if line)
if mode == 'copyData':
for acc in accountList:
[name,Id] = acc.strip().split(',')
name = name.strip()
#copyData(name, env['src_ror'], workingDir, env['dst_ror'], workingDir, 'bk_files', True)
copyData(name, env['src_ror'], workingDir, env['dst_ror'], workingDir, 'bk_files')
copyData(name, env['src_ror'], workingDir, env['dst_bpm'], backupDir, 'bk_files')
copyData(name, env['src_bpm'], workingDir, env['dst_bpm'], workingDir, 'ft_files')
localCopyData(name, env['dst_bpm'], workingDir, backupDir)
else:
#copy updated accountProfile from dst_ror to dst_bpm
fname = env['accountProfile']
# src = ip:port, dst = ip:port}
[sIp, sPort]=env['dst_ror'].split(':')
[dIp, dPort]=env['dst_bpm'].split(':')
copyFile(fname, sIp, sPort, toolDir, dPort, dIp, toolDir)