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

  • Home
  • SEARCH
  • 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 9269813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:12:59+00:00 2026-06-18T15:12:59+00:00

i had created a python program but it was not working. this program would

  • 0

i had created a python program but it was not working. this program would take in the input for a file and then display the file contents . the only error i was getting is a syntax error well i could not find the error . Please help me .
the code was :-

nm = input(“enter file name “)

str = raw_input(“enter ur text here: \n”)

f = open(nm,”w”)

f.write(str)

f.close()

print “1.See the file\n”

print “2.Exit\n”

s = input(“enter ur choice “)

if s == 1 :

    fi  = open(nm,”r”)

    cont  = fi.read()

for i in cont:

    print i

else :

    print “thank you “
  • 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-18T15:13:01+00:00Added an answer on June 18, 2026 at 3:13 pm

    The problem is that you are reading the filename using input() instead of raw_input(). See this answer that explains:

    If you use input, then the data you type is is interpreted as a Python
    Expression which means that you end up with gawd knows what type of
    object in your target variable, and a heck of a wide range of
    exceptions that can be generated. So you should NOT use input unless
    you’re putting something in for temporary testing, to be used only by
    someone who knows a bit about Python expressions.

    raw_input always returns a string because, heck, that’s what you
    always type in … but then you can easily convert it to the specific
    type you want, and catch the specific exceptions that may occur.
    Hopefully with that explanation, it’s a no-brainer to know which you
    should use.

    Also, since you are reading in the file contents by using fi.read(), your for loop for i in cont: will select each character of the file’s contents one at a time, instead of each line. Something to be aware of!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not a complete beginner but fairly new to Python . Whilst working
I had created a Lib Project with a class inherits ServiceBase but when I
I had created one HTML page for my experiance. In this i had use
I had created a zip file (together with directory) under Windows as follow (Code
This is what I want: I had created the top red layout by this
I have a program written in python, and I would like to make it
This is for Python 2.6. I could not figure out why a and b
I have created a program using python and wxpython. I have created an executable
I'm working on creating a python program to interact with many different types of
I had created one div window which is draggable,and created one child div (with

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.