Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9048407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:08:57+00:00 2026-06-16T12:08:57+00:00

What I am trying to do is read a list from a config file:

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T12:08:58+00:00Added an answer on June 16, 2026 at 12:08 pm

    Is this what you want?

    meal_allowed = tuple(('Hamburger', 2), ('Chicken', 3), ('Turkey', 4))
    

    Edit:

    For each meal:

    meals = ['hamburger', 'Turkey', 'Chicken']
    for meal in meals:
        rank = config[meal][rank]
    

    You must define what is the rank variable in rank = config[meal][rank]. After this, you may build a list of tuples, like:

    eatable = list()
    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.append((meal, rank))
    
    print eatable
    

    Anyway, shouldn’t you say “edible” instead of “eatable”? Or they’re both right? ^^

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read a list of values from a text file, hello.txt
I'm trying to read a list of strings from a file to an array.
I'm trying to read a list of items from a text file and format
I am trying to compare a list of forbidden folders read from a file.
I am trying to read a list of words from a file in C++.
I'm trying to read in a list of files from another file. The file
I'm trying to read a list of words from a txt file into a
I'm trying to read a list of numbers from a file and sort them
I'm trying to read a value from a list in a remote SharePoint site
I'm trying to create a list of tasks that I've read from some text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.