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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:49:00+00:00 2026-05-28T01:49:00+00:00

I have this .py file: from sys import argv script, filename = argv print

  • 0

I have this .py file:

from sys import argv

script, filename = argv

print "We're going to erase %r." % filename
print "If you don't want that, hit CTRL-C (^C)."
print "If you do want that, hit RETURN."

raw_input("?")

print "Opening the file..."
target = open(filename, 'w')

print "Truncating the file.  Goodbye!"
target.truncate()

print "Now I'm going to ask you for three lines."

line1 = raw_input("line 1: ")
line2 = raw_input("line 2: ")
line3 = raw_input("line 3: ")

print "I'm going to write these to the file."

target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")

print "And finally, we close it."
target.close()

What I do not understand:

a) Why in the interpreter if I write, raw_input("?"), then type f and press enter, it outputs the 'f' string and if I run the .py file it doesn’t return me the ‘f’ string?

b) Also, python docs says: ” The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. So, why does the line 7 gets printed on a new line instead of line 6(“?Opening the file…”). Where is that \n coming from?

  • 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-28T01:49:01+00:00Added an answer on May 28, 2026 at 1:49 am

    a) The interpreter prints the output of the commands by default, but your script doesn’t do that unless you use the print statement.

    print raw_input('?')
    

    b) The '\n' isn’t in the string returned from raw_input, but it’s anyway captured by the console when you press enter so this is a side effect you get when using raw_input.

    print repr(raw_input('?'))  # You'll get 'f', not 'f\n'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this trivial code: from sys import argv script, input_file = argv def
I received this python script that generates a file checksum: import sys,os if __name__==__main__:
I have bat-file, that make some operations. How to run this file from Delphi
I have a website that generates pdf file from CSP. Will this pdf file
I have one audio file captured from my iphone. I want to upload this
I have a web service that queries data from this json file, but I
i have the following script import getopt, sys opts, args = getopt.getopt(sys.argv[1:], h:s) for
I have this problem. Any idea? from OpenGL.raw.GLUT import * File /usr/lib/python2.6/site-packages/OpenGL/raw/GLUT/__init__.py, line 6,
I have this script that needs to replace a file extension and it is
I have this code which will include template.php file from inside each of these

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.