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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:04:34+00:00 2026-06-05T16:04:34+00:00

Simple question, I would like to append text to the front of every print

  • 0

Simple question, I would like to append text to the front of every print I call, for example if I set the text to hello and ran this:

print 'hello there'
print ' hi again'

It would print this:

hellohello there
hello hi again

Is there any way of doing this, without using a function to use that instead of print?

  • 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-05T16:04:36+00:00Added an answer on June 5, 2026 at 4:04 pm

    You could override print as per DevPlayer’s post here on StackOverflow, slightly modified here:

    from __future__ import print_function
    # Note: If you are using Python 3 leave this line out
    # This must be the first statement before other statements.
    # You may only put a quoted or triple quoted string, 
    # Python comments or blank lines before the __future__ line.
    import sys
    
    def print(*args, **kwargs):
        """My custom print() function."""
        # Adding new arguments to the print function signature 
        # is probably a bad idea.
        # Instead consider testing if custom argument keywords
        # are present in kwargs
        sys.stdout.write('hello')
        return __builtins__.print(*args, **kwargs)
    
    print ("hello there")
    print (" hi again")
    

    [Edit] …or as DSM suggests, you could avoid the sys call with this:

    from __future__ import print_function
    # Note: If you are using Python 3 leave this line out
    # This must be the first statement before other statements.
    # You may only put a quoted or triple quoted string, 
    # Python comments or blank lines before the __future__ line.
    
    def print(*args, **kwargs):
        """My custom print() function."""
        # Adding new arguments to the print function signature 
        # is probably a bad idea.
        # Instead consider testing if custom argument keywords
        # are present in kwargs
        __builtins__.print('hello',end='')
        return __builtins__.print(*args, **kwargs)
    
    print ("hello there")
    print (" hi again")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is hopefully a simple question: I have an OpenGL texture and would like
This is probably a simple question, but i would like to know how to
This may be a simple question but i would like some help to find
A simple answer to this super simple question would be great! Here is the
I know this is probably a very simple question but how would I do
i have a simple question: i have this var: $v = 24000,1500,1500,1500,1500,1500,; i would
This may sound like a simple question, but I just cannot seem to find
I feel like this is a stupid simple question, but I've been doing so
I have something simple like this: $(selector).append("somestuff"); But since I'm going to reuse the
A simple question, how would I go about declaring a clause which would produce

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.