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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:22:01+00:00 2026-05-22T12:22:01+00:00

At the start of a python file (first line) sometimes I read # -*-

  • 0

At the start of a python file (first line) sometimes I read

# -*- coding: utf-8 -*-

and sometimes I read

# encoding: utf-8

Both lines seem to do the same thing: specifying utf8 as encoding for all the text put in the file.

I have to questions:

  1. Why does this even work? I thought the interpreter ignores everything after a # because it invokes a comment.
  2. What is the difference between the two lines above? Does the interpreter just ignore the -*-?
  • 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-22T12:22:02+00:00Added an answer on May 22, 2026 at 12:22 pm

    The two forms are equivalent. The -*- version is a special kind of comment that Emacs understands. See PEP 263 for more information.

    If a comment like in either of these forms is one of the first two lines of a file, the interpreter will use the specified encoding to read the file.

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

Sidebar

Related Questions

I'm browsing through a Python file pointer of a text file in read-only mode
I want to start using Python for small projects but the fact that a
Should I start a Python program with: if__name__ == '__main__': some code... And if
I am about to start a personal project using python and I will be
If I was going to start an open source project using Python what version
I'm going to start of by noting that I have next to no python
What is the best way to start developing Windows Mobile Professional applications in Python?
I wrote an application server (using python & twisted) and I want to start
I start by creating a string variable with some non-ascii utf-8 encoded data on
Problem: ^.+ matches only the first line of the source code in dreamweaver. I

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.