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

The Archive Base Latest Questions

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

I am writing a test for a database which has Swedish characters in it.

  • 0

I am writing a test for a database which has Swedish characters in it. In the test, i directly use characters with umlauts and other such Swedish ligatures and it runs just fine, reading filenames in from a database and doing string compares successfully.

However, upon importing this file to do pydoc generation, i get the all-too-familiar exception:

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

Upon doing some investigation on my own, i found that adding

# -*- coding: iso-8859-15 -*-

to the top of my file fixed the importing problem. However, now the test fails all of the string comparisons. I tried the alternate method of forgoing the coding declaration and writing the strings as

u"Bokmärken"

… but this still doesn’t keep the test from failing.

Does anyone know a good way to fix 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-05-23T15:50:30+00:00Added an answer on May 23, 2026 at 3:50 pm

    You need to set your encoding in your editor and the database so that they match. If your database is utf-8 encoded, and not iso-8859-15, then setting your editor to utf-8 should fix it. However, since your u’string’ comparisons fail, this might not be the case.

    Replace

    # -*- coding: iso-8859-15 -*-
    

    with

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

    or (the equivalent)

    # coding=utf-8
    

    To try utf-8 encoding.

    Printing debugging output with repr('swedish string' and repr(u'swedish string') will also be useful in inspecting differences.
    Right after your interpreter line. Can you tell us what encoding your database is set to? Additionally, was the database data written by python or inserted directly? You could have written data in the wrong encoding to the database to begin with, which is now causing problems on comparison.

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

Sidebar

Related Questions

Does anyone have some good hints for writing test code for database-backend development where
I am writing a few test cases that depend on the database being available,
I'm writing a web app which is used a SaS. Each customer has their
I'm responsible for some test database servers. Historically, too many other poeple have access
I am writing a set of integration tests (Unit tests with MS Test which
I'm writing some code that has to cascade delete records in a certain database,
We want to design a simple domain specific language for writing test scripts to
Writing some test scripts in IronPython, I want to verify whether a window is
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
I'm writing a test for a file parser class. The parse method receives a

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.