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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:31:09+00:00 2026-05-30T15:31:09+00:00

I have trouble with Emacs+Python 2.7.1+Encoding. According to PEP 0263 , Python uses the

  • 0

I have trouble with Emacs+Python 2.7.1+Encoding. According to PEP 0263, Python uses the same declaration of source encoding as emacs does.

There is no problem when I start my Python source code script with the following encoding tag:

#!/usr/bin/python
# -*- mode=python; encoding:us-ascii -*-

But when I add a line ending mode to my encoding such as in:

#!/usr/bin/python
# -*- mode=python; encoding:us-ascii-unix -*-

Emacs still acepts my encoding information, but I get the following error from Python when executing my script:

File "./unicode.py", line 2
SyntaxError: encoding problem: with BOM

Is there a way to tell Emacs about the line ending I want to use and at the same time tell Python about the source file encoding?

  • 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-30T15:31:10+00:00Added an answer on May 30, 2026 at 3:31 pm

    You can write two blocks: one that is parsed only by the interpreter, and one that is only parsed by Emacs:

    #!/usr/bin/python
    # coding: us-ascii
    
    print "Hello World"    
    
    # Local Variables:
    # mode: python
    # coding: us-ascii-unix
    # End:
    

    Note that (1) us-ascii is the default in Python 2.x; and (2) Emacs is usually able to determine the line ending convention automatically; so you might be able to get along without declaring anything.

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

Sidebar

Related Questions

I have trouble finding way to correctly refactor this code so that there would
I have trouble choosing the right audio playback technology. There's a ton of technologies
I have trouble understanding the compilers. The following code does work in UNIX under
I have trouble with a query, the problem is that i am left joining
I'm having trouble inserting a buffer in Emacs. Say I have the following two
I have been trying to use emacs as a python IDE, I have tried
I have trouble finding the problem with the function below. The first parameters is
I have trouble comparing 2 double in Excel VBA suppose that I have the
I have trouble with the following piece of code. When I go through with
I have trouble using Perl grep() with a string that may contain chars that

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.