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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:27:25+00:00 2026-05-21T02:27:25+00:00

I am a python noob, and am having problems running programs with open() functions

  • 0

I am a python noob, and am having problems running programs with open() functions in cmd prompts. The code runs as expected in the python shell with IDLE, but everytime I open it by doubleclicking the icon coresponding to the script( I have .py associated with python), I get errors like

what file test.txt (I entered input)
file 2 atest2.txt (I entered intput)
Traceback (most recent call last):
File "C:\Users\Matthew\Desktop\file_io\find_differences_in_files.py", line 3,
in <module>
f=open(c,"r") # open c
IOError: [Errno 22] Invalid argument: 'test.txt\r'

Similar problems occur in multiple similar programs, but here is a sample of code( FYI, this code finds the first difference in two .txt files) that worked in IDLE but not in cmd. Anybody have any clue what is going wrong?

c=input("what file") # get file 1  
d=input("file 2") # get file 2  
f=open(c,"r") # open c   
g=open(d,"r") # open d  
p=f.readlines() # get every line of f   
q=g.readlines()   
i=0  
while i<len(p) and i<len(q):  
    if p[i]!=q[i]:   
        break # stop counting up  
    i+=1  
x=p[i] # store different line  
y=q[i] # store different line  
j=0  
while j<len(x) or i<len(y):       
    if x[j]!=y[j]:   
        break # stop counting up  
    j+=1  
print("The difference is in line %s column %s" % (i+1,j+1))  
c=input("press enter")
  • 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-21T02:27:26+00:00Added an answer on May 21, 2026 at 2:27 am

    You’re not handling end-of-line characters correctly, and IDLE gives you the end-of-line in one format, while the cmd.exe sends another.

    I suggest stripping whitespace from both ends of the input in this case.

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

Sidebar

Related Questions

I am a noob when it comes to python. I have a python script
I'm a total python noob so please bear with me. I want to have
Python noob here, Currently I'm working with SQLAlchemy, and I have this: from __init__
Python noob trying to learn Pylons. I'm using the QuickWiki tutorial ( http://pylonshq.com/docs/en/1.0/tutorials/quickwiki_tutorial/ )
I'm a complete Python noob. How can I remove two characters from the beginning
I am a Python noob. I create a class as follows: class t1: x
Does iPython work on Mac OS X 10.6.1 Snow Leopard? I'm python noob, how
Python's f.tell doesn't work as I expected when you iterate over a file with
I'm a python noob and I'm getting to grips with python via 'Python Programming
Django/Python noob here! Here are my models: class Match(models.Model): date = models.DateTimeField() court =

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.