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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:46:30+00:00 2026-06-08T18:46:30+00:00

with open(path) as f: for line in f: print line path is file with

  • 0
    with open(path) as f:
        for line in f:
            print line

path is file with single line as \xc2

when I run this I get

\xc2

now lets change this

with open(path) as f:
    for line in f:
                var = '\xc2'
                print var

When I run this, I see

UnicodeDecodeError: 'ascii', '\xc2d', 0, 1, 'ordinal not in range(128)'

then I try to compare the so I do

with open(path) as f:
    for line in f:
        line = line.strip()
        line1 = '\xc2d'
        # print line1
        print line == line1

and I see False

What is happening here??

  • 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-08T18:46:32+00:00Added an answer on June 8, 2026 at 6:46 pm

    When you read characters from a file, \ is just another character and has no special meaning. When you try to create a string from it though, it’s used as an escape that has special meanings depending on what follows. For example \x means take the next 2 hex digits and create the character that corresponds to the hex code, thus '\xc2' is a single character. Since this character code isn’t in the ASCII range of 0 to 127 (0x7f), you get an error when you try to print it.

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

Sidebar

Related Questions

The docs for django.core.files.File imply I can do this: print File(open(path)).url but the File
I'm printing the first line from a file: with open(path,r,encoding='utf8') as f: for i,
f= File.open('path_to_file','w') f.lineno #=> 0 f.gets #=>this is the content of the first line
Consider the following: with open(path, mode) as f: return [line for line in f
import os listing = os.listdir(path) for infile in listing: print infile f = open(os.path.join(path,
My file looks like this: <MAIN> <SUB_MAIN>one</SUB_MAIN> <VER>version#</VER> (OTHER STUFF...) <LOCATION>PATH</LOCATION> </MAIN> <MAIN> <SUB_MAIN>two</SUB_MAIN>
I have the following code: f = open(path, 'r') html = f.read() # no
Trying to read headers for a csv file with: reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers =
I want open a path to vim from Screen's copy-mode by Ctrl-A f similarly
I have the following code: using (BinaryReader br = new BinaryReader( File.Open(FILE_PATH, FileMode.Open, FileAccess.ReadWrite)))

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.