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

  • Home
  • SEARCH
  • 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 6643843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:05:51+00:00 2026-05-26T00:05:51+00:00

With Python ConfigParser, is it possible to use interpolation across foreign sections? My mind

  • 0

With Python ConfigParser, is it possible to use interpolation across foreign sections? My mind seems to tell me I’ve seen that it’s possible somewhere, but I can’t find it when searching.

This example doesn’t work, but it’s to give an idea of what I’m trying to do.

[section1]
root = /usr

[section2]
root = /usr/local

[section3]
dir1 = $(section1:root)/bin
dir2 = $(section2:root)/bin

Note that I’m using Python 2.4.

  • 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-05-26T00:05:51+00:00Added an answer on May 26, 2026 at 12:05 am

    In python 3.2 and up this is perfectly valid:

    [Common]
    home_dir: /Users
    library_dir: /Library
    system_dir: /System
    macports_dir: /opt/local
    
    [Frameworks]
    Python: 3.2
    path: ${Common:system_dir}/Library/Frameworks/
    
    [Arthur]
    nickname: Two Sheds
    last_name: Jackson
    my_dir: ${Common:home_dir}/twosheds
    my_pictures: ${my_dir}/Pictures
    python_dir: ${Frameworks:path}/Python/Versions/${Frameworks:Python}
    

    Edit:

    I just saw that you are using python 2.4, so no, section interpolation cannot be done in python 2.4. It was introduced in python 3.2 – See section 13.2.5 – ConfigParser Interpolation of values.

    class configparser.ExtendedInterpolation

    An alternative handler
    for interpolation which implements a more advanced syntax, used for
    instance in zc.buildout. Extended interpolation is using
    ${section:option} to denote a value from a foreign section.
    Interpolation can span multiple levels. For convenience, if the
    section: part is omitted, interpolation defaults to the current
    section (and possibly the default values from the special section).
    For example, the configuration specified above with basic
    interpolation, would look like this with extended interpolation:

       [Paths]
       home_dir: /Users
       my_dir: ${home_dir}/lumberjack
       my_pictures: ${my_dir}/Pictures
    

    Values from other sections can be fetched as well:

       [Common]
       home_dir: /Users
       library_dir: /Library
       system_dir: /System
       macports_dir: /opt/local
    
       [Frameworks]
       Python: 3.2
       path: ${Common:system_dir}/Library/Frameworks/
    
       [Arthur]
       nickname: Two Sheds
       last_name: Jackson
       my_dir: ${Common:home_dir}/twosheds
       my_pictures: ${my_dir}/Pictures
       python_dir: ${Frameworks:path}/Python/Versions/${Frameworks:Python}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to use Python's ConfigParser module to save settings. For my app
The documentation for ConfigParser in Python talks a lot about the so-called magical interpolation
I'm creating a subclass of ConfigParser that is easier for me to use throughout
Python's convention is that variables are created by first assignment, and trying to read
python's time module seems a little haphazard. For example, here is a list of
I am writing a wrapper for the ConfigParser in Python to provide an easy
I have a python class which reads a config file using ConfigParser: Config file:
I'm new to python, and I've been reading that using global to pass variables
Python's f.tell doesn't work as I expected when you iterate over a file with
In python how can I create a function that can be global an used

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.