Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude one argument from argparser

Can I define all except one argument for one the option in python?

I want to shutdown all hosts in lab except one host. For argparser I have given -h ^server1 which should be pick all hosts from host list except server1.

like image 444
user1756067 Avatar asked Feb 06 '26 13:02

user1756067


1 Answers

Something simple. Remove any hosts from the list that start with ^. Call some sort of shutdown function for each host name in the revised list.

hostlist = [x for x in hostlist if not x.startswith('^')]
map(shutdownhost, hostlist)
like image 170
Aesthete Avatar answered Feb 08 '26 03:02

Aesthete



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!