Jul-25-2020, 12:08 PM
Hi Support,
I have one csv file and some field is blank. now i m writing code to read csv file and if filed is blank then take the input from the user and write in csv.
CSV Format:
I have one csv file and some field is blank. now i m writing code to read csv file and if filed is blank then take the input from the user and write in csv.
CSV Format:
Output:AccountId RegionName SubnetID OS_Name KeyName
eastus demo_subnet server2012 window_keyname
import csv reader = csv.DictReader(open("D:\python_Step_Step_Lab\Book1.csv")) for raw in reader: print(raw) test=(raw['AccountId']) test01=(raw['RegionName']) test02=(raw['SubnetID']) test03=(raw['OS_Name']) test04=(raw['KeyName']) if test == '': print("Enter the AccountId: " ) # Required input from user and store in csv elif test01='': print("Enter the RegionName: ") # Required input from user and store in csv elif test02='': print("Enter the Subnet ID: ") # Required input from user and store in csv elif test03='': print("Enter the OS_Name: ") # Required input from user and store in csv elif test04='': print("Enter the KeyName: ") # Required input from user and store in csv else: print("All parameter is Correct") with open("D:\python_Step_Step_Lab\Book1.csv", 'w') as csvfile: # Store the input in same file Book1.csv