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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:19:06+00:00 2026-06-10T08:19:06+00:00

I read a file which has a line : Fixes: Saurabh Likes python I

  • 0

I read a file which has a line : Fixes: Saurabh Likes python

I want to remove the Fixes: part of above line. I am employing regex for that
but the snippet below returns output like

Saurabh Likes python\r

I am wondering where \r is coming from. I tried all strip options for removing it like rstrip(), lstrip(), etc. But nothing worked. Could anybody suggest me the way to get rid of \r.

patternFixes ='\s*'+'Fixes'+':'+'\s*'
matchFixes= re.search(patternFixes,line, re.IGNORECASE)
        if matchFixes:
                    patternCompiled = re.compile(patternFixes)
                    line=patternCompiled.sub("", line)
                    #line=line.lstrip()
                    relevantInfo = relevantInfo+line
                    continue

Thanks in advance!
-Saurabh

  • 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-10T08:19:08+00:00Added an answer on June 10, 2026 at 8:19 am

    Suggestion to get rid of \r:

    I suppose you have opened your file using open(filename). Following the manual of open:

    If mode is omitted, it defaults to ‘r’. … In addition to the
    standard fopen() values mode may be ‘U’ or ‘rU’. Python is usually
    built with universal newlines support; supplying ‘U’ opens the file as
    a text file, but lines may be terminated by any of the following: the
    Unix end-of-line convention ‘\n’, the Macintosh convention ‘\r’, or
    the Windows convention ‘\r\n’. All of these external representations
    are seen as ‘\n’ by the Python program.

    So, in short, please try to open your file using 'rU' and see if the \r vanishes:

    with open(filename, "rU") as f:
        # do your stuff here.
        ...
    

    Does the \r vanish in your output?

    Of course your code looks rather clunky, but other have already commented on this part.

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

Sidebar

Related Questions

I am new to Python and wanted to read a file, which has even
I have a file from which i read line by line and i have
I have a text file which has first line as below: j0W82LBrSdUbw Basically it
I am trying to read a html file which is a plain page with
I have this file which I need to read the first bytes to check
Assume that we have a large file which can be read in chunks of
I am trying to read the file with the following format which repeats itself
I'd like to read an xml file on a user's machine (which can be
I have a sed script which will read in a file and, if a
I've got a file (test.txt) which contains 1234567. However when I try to read

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.