lundi 29 juin 2020

How to conditionally check string in IF condition python [duplicate]

I am have a variable called vol_dev value will be like this (it can be any value out of these )

/dev/sda1 or /dev/sdb or /dev/sdc like this , I need to perform set of action based on above values in if condition.

so I using re module to like below. the idea is to check if there is pattern like sda1 in vol_dev or not. any other pattern other than sda1 in vol_dev I need to do different set of action.

vol_dev = res_vol['Volumes'][0]['Attachments'][0]['Device']    
if re.search(r'sda1', vol_dev):
   print(vol_dev)

How to specify NOT condition in search pattern ? i.e search other than sda1 in above if condition. The problem i need to decide based on pattern in vol_dev variable.

Any suggestion would be highly appreciated

Aucun commentaire:

Enregistrer un commentaire