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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:49:41+00:00 2026-06-05T21:49:41+00:00

I am currently parsing large text files with Python 2.7, some of which were

  • 0

I am currently parsing large text files with Python 2.7, some of which were originally encoded in Unicode or UTF-8.

For modules containing functions which directly interact with strings in UTF-8, I included # -*- coding: utf-8 -*- at the top of the file, but for functions which work with only ascii, I did not bother.

Eventually, these modules lead to larger modules, and all the parsed strings gets mixed together. Is it good practice to include # -*- coding: utf-8 -*- at top of every file?

Is there a benefit to this?

  • 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-05T21:49:43+00:00Added an answer on June 5, 2026 at 9:49 pm

    # -*- coding: utf-8 -*- declares the encoding of the source file only. It has nothing to do whatsoever with the way Python handles input or output. It just means you can write string literals and comments using UTF-8.

    Here’s the effect of a coding declaration. Let’s say I have a program

    # -*- coding: utf-8 -*-
    # the following prints the Dutch word "één"
    print(u"\xe9\xe9n")
    

    This does exactly what the comment says. But if I remove the coding declaration, it crashes:

    File "a.py", line 1
    SyntaxError: Non-ASCII character '\xc3' in file a.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
    

    Note that line 1 is the comment. The program can be fixed by removing the comment, leaving just

    print(u"\xe9\xe9n")
    

    which still behaves exactly the same as the first program.

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

Sidebar

Related Questions

Currently, I am parsing some UNSTRUCTURED text and CONVERT IT TO THIS: Type1 Type1
I am currently parsing a large number of zone files at my work so
How are you currently parsing ISO8601 dates e.g. 2010-02-23T23:04:48Z in JavaScript? Some browsers return
My map is currently inefficient when parsing one particular set of files (a total
How can I know during parsing which rule is currently matched? I'd like to
I'm currently passing some date-time info to a web page using url parameters, which
There are two large text files (Millions of lines) that my program uses. These
At work I am parsing large XML files using the DefaultHandler class. Doing that,
In 2010, would you serve URLs containing UTF-8 characters in a large web portal?
First some background, I am currently working on a relatively large Asp.Net MVC application

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.