What I am trying to do is read a list from a config file:
import re
from configobj import ConfigObj
config = ConfigObj('food.conf')
meal_list = config['MainConfig']['MealList']
The MealList section in the config looks like Turkey|Hamburger|Chicken etc etc.
After that I need to run each of them through:
for meal in meal_list:
if re.search( config[meal][ingredients]['Allowlist'], badingredients, re.M|re.I):
Here comes my first problem. How do I join them correctly? Beacuse after this for part, I pass them to a rank function. So how do I join the “allowed” ones into a tuple?
The rank is also defined in the in the config file.
meal_allowed = ('Hamburger', 2),('Chicken', 3),('Turkey', 4)
food = sorted(meal_allowed, key=lambda student: student[1])
food_to_eat = str(food).translate(None, "-[]()'0123456789").replace(" ", "").replace(",,",",")
print food_to_eat
So in short how do I use .join() and then turn it in to tuples?
Edit
Another example of what i am looking for.
meals = 'hamburger', 'Turkey', 'Chicken'
for meal in meals:
rank = config[meal][rank]
if re.search( config[meal][ingredients]['Allowlist'], badingredients, re.M|re.I):
eatable = meal + meal + rank
eatable should be (‘Hamburger’, 2),(‘Chicken’, 3),(‘Turkey’, 4) format.
Else i cant rank it.
Is this what you want?
Edit:
For each
meal:You must define what is the
rankvariable inrank = config[meal][rank]. After this, you may build a list of tuples, like:Anyway, shouldn’t you say “edible” instead of “eatable”? Or they’re both right? ^^