I’m trying to match values of a list to a regex pattern. If the particular value within the list matches, I’ll append it to a different list of dicts. If the above mentioned value does not match, I want to remove the value from the list.
import subprocess
def list_installed():
rawlist = subprocess.check_output(['yum', 'list', 'installed']).splitlines()
#print rawlist
for each_item in rawlist:
if "[\w86]" or \
"noarch" in each_item:
print each_item #additional stuff here to append list of dicts
#i haven't done the appending part yet
#the list of dict's will be returned at end of this funct
else:
remove(each_item)
list_installed()
The end goal is to eventually be able to do something similar to:
nifty_module.tellme(installed_packages[3]['version'])
nifty_module.dosomething(installed_packages[6])
Note to gnu/linux users going wtf:
This will eventually grow into a larger sysadmin frontend.
Despite the lack of an actual question in your post, I’ll make a couple of comments.
You have a problem here:
It’s not interpreted the way you think of it and it always evaluates to
True. You probably needAlso, I’m not sure what you are doing, but in case you expect that Python will do regex matching here: it won’t. If you need that, look at
remodule.remove(each_item)I don’t know how it’s implemented, but it probably won’t work if you expect it to remove the element from
rawlist:removewon’t be able to actually access the list defined insidelist_installed. I’d advise to userawlist.remove(each_item)instead, but not in this case, because you are iterating overrawlist. You need to re-think the procedure a little (create another list and append needed elements to it instead of removing, for example).