def ssh_login_xxx(host_ip): do the login stuf def ssh_login_yyy(host_ip): do the login stuf def ssh_login_zzz(host_ip): do the login stuf login_functions = {'xxx':ssh_login_xxx, 'yyy':ssh_login_yyy, 'zzz':ssh_login_xxx} with open (input_file, 'r') as my_file: csv_reader = csv.DictReader(my_file) for line in csv_reader: dev_model = line['dev_model'] host_ip = line['host_ip'] sub = dev_model if sub == dev_model: login_function = login_functions[sub] function_name(host_ip)You can define dict of login functions (look above). However do you realy need separate functions. Can you pass target (xxx, yyy, zzz) as argument (is the process of logging in fundamentally different?)
Also:
sub = dev_model if sub == dev_model:This doesn't make sense at all, condition will always be
True
Better replace
sub = dev_model if sub == dev_model: login_function = login_functions[sub] function_name(host_ip)with
try: login_function = login_functions[sub] function_name(host_ip) except KeyError: print(f'Unknown device model: {dev_model}')
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs