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 6319947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:53:14+00:00 2026-05-24T15:53:14+00:00

I am searching for a Python library for string formatting with custom placeholders. What

  • 0

I am searching for a Python library for string formatting with custom placeholders. What I mean is that I would like to be able to define a string like "%f %d %3c" where for example %f would be then replaced with some filename, %d with a directory name and %3c with a counter with three digits. Or something. It does not have to be printf-like but it would be great if it would be. So I would like to be able to define what each letter means, is it string or number, and also some formatting (like number of digits) data.

The idea is that user can specify the format and I then fill it in with data. Like datefmt works. But for custom things.

Is there something like that already made for Python (2.5+, sadly not for 2.7 and 3 and its __format__)?

  • 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-24T15:53:17+00:00Added an answer on May 24, 2026 at 3:53 pm

    There is string.Template, but it doesn’t provide exactly what you want:

    >>> from string import Template
    >>> t = Template("$filename $directory $counter")
    >>> t.substitute(filename="file.py", directory="/home", counter=42)
    'file.py /home 42'
    >>> t.substitute(filename="file2.conf", directory="/etc", counter=8)
    'file2.conf /etc 8'
    

    Documentation: http://docs.python.org/library/string.html#template-strings

    But I think this provides what you need. Just specify a template string and use this:

    >>> template = "%(filename)s %(directory)s %(counter)03d"
    >>> template % {"filename": "file", "directory": "dir", "counter": 42}
    'file dir 042'
    >>> template % {"filename": "file2", "directory": "dir2", "counter": 5}
    'file2 dir2 005'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this python library that implements the Aho-Corasick string searching algorithm that
I'm searching for a workflow library/framework for Python. I'm astonished that there I cannot
I'm searching for a library that can extract (at least) the following information from
I tried to a library via easy_install like following: $ sudo easy_install bbfreeze Searching
I'm searching for an easy to handle python native module to create python object
Searching for a string within a string is extremely well supported in .NET but
Searching here I found that this question was already asked , but I think
Searching from google.com, like www.abc.com Search Result Rank the pages like Title..... Description... www.abc.com
After finding the difflib.SequenceMatcher class in Python's standard library to be unsuitable for my
After finding the difflib.SequenceMatcher class in Python's standard library to be unsuitable for my

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.