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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:05:15+00:00 2026-06-12T02:05:15+00:00

All my python source code is encoded in utf-8 and has this coding declared

  • 0

All my python source code is encoded in utf-8 and has this coding declared on the top of the file.

But sometimes the u before a unicode string is missing.

Example Umlauts = "üöä"

Above is a bytestring containing non-ascii characters and this makes trouble (UnicodeDecodeError).

I tried pylint and python -3 but I could not get a warning.

I search an automated way to find non-ascii characters in bytestrings.

My source code needs to support Python 2.6 and Python 2.7.

I get this well known error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128)

BTW: This question is only about python source code, not about strings read from files or sockets.

Solution

  • for projects which need to support Python 2.6+ I will use __future__.unicode_literals
  • for projects which need to support 2.5 I will use the solution from thg435 (module ast)
  • 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-12T02:05:16+00:00Added an answer on June 12, 2026 at 2:05 am

    Of course you want to use python for this!

    import ast, re
    
    with open("your_script.py") as fp:
        tree = ast.parse(fp.read())
    
    for node in ast.walk(tree):
        if (isinstance(node, ast.Str) 
                and isinstance(node.s, str) 
                and  re.search(r'[\x80-\xFF]', node.s)):
            print 'bad string %r line %d col %d' % (node.s, node.lineno, node.col_offset)
    

    Note that this doesn’t distinguish between bare and escaped non-ascii chars (fuß and fu\xdf).

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

Sidebar

Related Questions

Given the source code of a Python file, I would like to detect all
I have some source code file which has mixed tabs/spaces and I want to
I've seen it a lot in python/Lib source code but I don't know what
Can I eliminate all Python loops in this computation: result[i,j,k] = (x[i] * y[j]
I don't program in Python at all, so please forgive my code. I am
Possible Duplicate: Python code to pick out all possible combinations from a list? I
I've noticed that I can not use all unicode characters in my python source
I was trying to PCM sound a little bit in Python, but all the
The documentation of the API shows source code on how to accomplish this in
My python env is 2.7 I know this is an old question, but I've

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.