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

The Archive Base Latest Questions

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

I do this a lot in Perl: printf %8s %8s %8s\n, qw(date price ret);

  • 0

I do this a lot in Perl:

printf "%8s %8s %8s\n", qw(date price ret);

However, the best I can come up with in Python is

print '%8s %8s %8s' % (tuple("date price ret".split()))

I’m just wondering if there is a more elegant way of doing it? I’m fine if you tell me that’s it and no improvement can be made.

  • 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:41:56+00:00Added an answer on May 16, 2026 at 8:41 am

    Well, there’s definitely no way to do exactly what you can do in Perl, because Python will complain about undefined variable names and a syntax error (missing comma, perhaps). But I would write it like this (in Python 2.X):

    print '%8s %8s %8s' % ('date', 'price', 'ret')
    

    If you’re really attached to Perl’s syntax, I guess you could define a function qw like this:

    def qw(s):
        return tuple(s.split())
    

    and then you could write

    print '%8s %8s %8s' % qw('date price ret')
    

    which is basically Perl-like except for the one pair of quotes on the argument to qw. But I’d hesitate to recommend that. At least, don’t do it only because you miss Perl – it only enables your denial that you’re working in a new programming language now 😉 It’s like the old story about Pascal programmers who switch to C and create macros

    #define BEGIN {
    #define END   }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there is a lot on this topic but I can't get any
I have been hearing a lot about this Modern Perl. What is it? One
I come to ask for your aid after a lot of research on this
A lot of times in Perl, I'll do something like this: $myhash{foo}{bar}{baz} = 1
I'm very new to this Parallel::ForkManager module in Perl and it has a lot
I use this a lot NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES comparator:^(id obj1, id
I have been seeing this a lot lately and I am unable to find
I am new to stackoverflow as a member, although I follow this a lot
This is a lot more complicated than it might seem at first. What I
use this website a lot but first time posting. My program creates a number

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.