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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:49:45+00:00 2026-05-16T08:49:45+00:00

Someone has recently demonstrated to me that we can print variables in Python like

  • 0

Someone has recently demonstrated to me that we can print variables in Python like how Perl does.

Instead of:

print("%s, %s, %s" % (foo, bar, baz))

we could do:

print("%(foo)s, %(bar)s, %(baz)s" % locals())

Is there a less hacky looking way of printing variables in Python like we do in Perl? I think the 2nd solution actually looks really good and makes code a lot more readable, but the locals() hanging around there makes it look like such a convoluted way of doing 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-05-16T08:49:46+00:00Added an answer on May 16, 2026 at 8:49 am

    The only other way would be to use the Python 2.6+/3.x .format() method for string formatting:

    # dict must be passed by reference to .format()
    print("{foo}, {bar}, {baz}").format(**locals()) 
    

    Or referencing specific variables by name:

    # Python 2.6
    print("{0}, {1}, {2}").format(foo, bar, baz) 
    
    # Python 2.7/3.1+
    print("{}, {}, {}").format(foo, bar, baz)    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently, Google has created a new Search API that you can integrate into your
Someone has an answer to this missing feature in Entity Framework. Does anyone have
If someone has deleted the remote branch, is there any way I can pull
I wonder whether someone has an idea for how to count combinations like the
I'm hoping someone has run into this sort of problem before, and can give
Recently the State Department has released a document saying that AES and DES are
It looks like the Yahoo Boss API terms of service has recently changed to
A vulnerability has recently been disclosed that affects WordPress 2.8.3 and allows the admin
I've recently been working with someone else's code and I realized that this individual
I'm hoping someone can help me. I recently started the development of a windows

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.