jeudi 19 septembre 2019

Better way to check varible to avoid multiple conditions for multiple varibles

I have below example code where it has three variable defined job_Name out_File err_File.

Now I'm looking to remove this from print statement if any of the variable or all the variables either empty ot not defined

job_Name = "Test"
out_File = "/tmp/123"
err_File = "/tmp/321"

print("Job Name {0},Output {1}, Error {2}".format(job_Name,out_File,err_File))

ie: if job_Name is empty it should print :

Output  Error
/tmp/123 /tmp/321

Let suppose out_File and err_File not defined it should only print job_Name.

Job Name 
Test

This can be done with chain conditions if else etc.. but looking if that can be avoid as we have multiple such variables and achieved with some smarter or other elegant way.

Aucun commentaire:

Enregistrer un commentaire