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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:25:19+00:00 2026-06-18T02:25:19+00:00

I´m new to programming, but I know how to Google, so I dare to

  • 0

I´m new to programming, but I know how to Google, so I dare to ask you for help on this one after a lot of trial and error.

I have a MySQL database (db name: text, table name: text) with utf-8 encoded text (Swedish) that I want to fetch into IPython Notebook using mysql-python (MySQLdb) for further processing.

I’ve read the python documentation about Unicode and UTF-8 (http://docs.python.org/2/howto/unicode.html), but I haven´t been able to find concrete code examples even though this must be a very trivial problem.

I just want the text in Swedish to show up in IPython Notebook with special characters åäö etc. As you can see I´ve put in more or less every code snippet I´ve found on the web regarding Unicode and UTF-8, but I can´t understand where I do the mistake(s)?

Can someone please help me out?

# -*- coding: utf-8 -*-
import MySQLdb
db = MySQLdb.connect('localhost', 'user', 'password', 'text', charset='utf8', use_unicode=False)
db.set_character_set('utf8')
cursor = db.cursor()
cursor.execute('SET NAMES utf8')
cursor.execute('SET CHARACTER SET utf8')
cursor.execute('SELECT title, body FROM text LIMIT 5') 
result=cursor.fetchall()
 print result

Update: This is what I get back from the Print statement:
((‘F\xc3\xb6rsta rubriken’, ‘H\xc3\xa4r \xc3\xa4r lite text p\xc3\xa5 svenska’), (‘Andra rubriken’, ‘Ytterligare lite text p\xc3\xa5 ett annat spr\xc3\xa5k’))

  • 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-18T02:25:20+00:00Added an answer on June 18, 2026 at 2:25 am

    You are printing the result of the cursor call, which is a tuple; and you are seing the Python representation of it.

    If you loop through it, you’ll see your expected results:

    >>> for i in result:
    ...    print "{} {}".format(*i)
    ... 
    Första rubriken Här är lite text på svenska
    Andra rubriken Ytterligare lite text på ett annat språk
    

    If your output doesn’t match the above, this means your terminal doesn’t support UTF-8.

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

Sidebar

Related Questions

I am kind of new to programming but I already do know a lot.
I am really new to the programming but I am studying it. I have
I'm new to Android & Java programming but have been programming in .NET for
This is a kind of a newb question but I'm really new to programming
I don't know what the proper name for this sort of programming, but all
I have long programming background, but am new to Python, and am playing around
I'm still relatively new to Perl Programming, but I know how Perl 5 OO
Im new to programming and I dont know very much about but I'm making
[I'm sorry that this isn't directly a programming question. But I have recently switched
Disclaimer: I am new to python and django but have Drupal programming experience. I'm

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.