Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

fix syntax highlighting
Source Link
Fynn Becker
  • 1.4k
  • 2
  • 20
  • 25

The unicode strings it's outputting are perfectly fine. You can verify this by trying print u'ThisTextIsBr\xf8ken' in a python shell:

➜ python2
Python 2.7.15 (default, Jan 10 2019, 23:20:52)
[GCC 8.2.1 20181127] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'ThisTextIsBr\xf8ken'
ThisTextIsBrøken
➜ python2
Python 2.7.15 (default, Jan 10 2019, 23:20:52)
[GCC 8.2.1 20181127] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'ThisTextIsBr\xf8ken'
ThisTextIsBrøken

Your confusion is merely about how python represents unicode strings that are wrapped in another object. In this case your rows each represent a tuple of columns or more specifically a tuple containing a single unicode string.

You can verify this by adjusting your code to print the actual unicode string rather than the tuple containing it.

# -*- coding: UTF-8 -*-
import pymysql
db = pymysql.connect(
 host="localhost",
 user="root",
 password="XXXXXXXX",
 db="pythonconnectiontest", 
 charset="utf8"
)
cursor = db.cursor()
cursor.execute("SELECT Username FROM Account")
numrows = cursor.rowcount 
for i in range (numrows):
 row = cursor.fetchone()
 print row[0]
# -*- coding: UTF-8 -*-
import pymysql
db = pymysql.connect(
 host="localhost",
 user="root",
 password="XXXXXXXX",
 db="pythonconnectiontest", 
 charset="utf8"
)
cursor = db.cursor()
cursor.execute("SELECT Username FROM Account")
numrows = cursor.rowcount 
for i in range (numrows):
 row = cursor.fetchone()
 print row[0]

This should now output the expected strings.

The unicode strings it's outputting are perfectly fine. You can verify this by trying print u'ThisTextIsBr\xf8ken' in a python shell:

➜ python2
Python 2.7.15 (default, Jan 10 2019, 23:20:52)
[GCC 8.2.1 20181127] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'ThisTextIsBr\xf8ken'
ThisTextIsBrøken

Your confusion is merely about how python represents unicode strings that are wrapped in another object. In this case your rows each represent a tuple of columns or more specifically a tuple containing a single unicode string.

You can verify this by adjusting your code to print the actual unicode string rather than the tuple containing it.

# -*- coding: UTF-8 -*-
import pymysql
db = pymysql.connect(
 host="localhost",
 user="root",
 password="XXXXXXXX",
 db="pythonconnectiontest", 
 charset="utf8"
)
cursor = db.cursor()
cursor.execute("SELECT Username FROM Account")
numrows = cursor.rowcount 
for i in range (numrows):
 row = cursor.fetchone()
 print row[0]

This should now output the expected strings.

The unicode strings it's outputting are perfectly fine. You can verify this by trying print u'ThisTextIsBr\xf8ken' in a python shell:

➜ python2
Python 2.7.15 (default, Jan 10 2019, 23:20:52)
[GCC 8.2.1 20181127] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'ThisTextIsBr\xf8ken'
ThisTextIsBrøken

Your confusion is merely about how python represents unicode strings that are wrapped in another object. In this case your rows each represent a tuple of columns or more specifically a tuple containing a single unicode string.

You can verify this by adjusting your code to print the actual unicode string rather than the tuple containing it.

# -*- coding: UTF-8 -*-
import pymysql
db = pymysql.connect(
 host="localhost",
 user="root",
 password="XXXXXXXX",
 db="pythonconnectiontest", 
 charset="utf8"
)
cursor = db.cursor()
cursor.execute("SELECT Username FROM Account")
numrows = cursor.rowcount 
for i in range (numrows):
 row = cursor.fetchone()
 print row[0]

This should now output the expected strings.

added 241 characters in body
Source Link
Fynn Becker
  • 1.4k
  • 2
  • 20
  • 25

The unicode strings it's outputting are perfectly fine. You can verify this by trying print u'ThisTextIsBr\xf8ken' in a python shell.:

➜ python2
Python 2.7.15 (default, Jan 10 2019, 23:20:52)
[GCC 8.2.1 20181127] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'ThisTextIsBr\xf8ken'
ThisTextIsBrøken

Your confusion is merely about how python represents unicode strings that are wrapped in another object. In this case your rows each represent a tuple of columns or more specifically a tuple containing a single unicode string.

You can verify this by adjusting your code to print the actual unicode string rather than the tuple containing it.

# -*- coding: UTF-8 -*-
import pymysql
db = pymysql.connect(
 host="localhost",
 user="root",
 password="XXXXXXXX",
 db="pythonconnectiontest", 
 charset="utf8"
)
cursor = db.cursor()
cursor.execute("SELECT Username FROM Account")
numrows = cursor.rowcount 
for i in range (numrows):
 row = cursor.fetchone()
 print row[0]

This should now output the expected strings.

The unicode strings it's outputting are perfectly fine. You can verify this by trying print u'ThisTextIsBr\xf8ken' in a python shell.

Your confusion is merely about how python represents unicode strings that are wrapped in another object. In this case your rows each represent a tuple of columns.

You can verify this by adjusting your code to print the actual unicode string rather than the tuple containing it.

# -*- coding: UTF-8 -*-
import pymysql
db = pymysql.connect(
 host="localhost",
 user="root",
 password="XXXXXXXX",
 db="pythonconnectiontest", 
 charset="utf8"
)
cursor = db.cursor()
cursor.execute("SELECT Username FROM Account")
numrows = cursor.rowcount 
for i in range (numrows):
 row = cursor.fetchone()
 print row[0]

This should now output the expected strings.

The unicode strings it's outputting are perfectly fine. You can verify this by trying print u'ThisTextIsBr\xf8ken' in a python shell:

➜ python2
Python 2.7.15 (default, Jan 10 2019, 23:20:52)
[GCC 8.2.1 20181127] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'ThisTextIsBr\xf8ken'
ThisTextIsBrøken

Your confusion is merely about how python represents unicode strings that are wrapped in another object. In this case your rows each represent a tuple of columns or more specifically a tuple containing a single unicode string.

You can verify this by adjusting your code to print the actual unicode string rather than the tuple containing it.

# -*- coding: UTF-8 -*-
import pymysql
db = pymysql.connect(
 host="localhost",
 user="root",
 password="XXXXXXXX",
 db="pythonconnectiontest", 
 charset="utf8"
)
cursor = db.cursor()
cursor.execute("SELECT Username FROM Account")
numrows = cursor.rowcount 
for i in range (numrows):
 row = cursor.fetchone()
 print row[0]

This should now output the expected strings.

Source Link
Fynn Becker
  • 1.4k
  • 2
  • 20
  • 25

The unicode strings it's outputting are perfectly fine. You can verify this by trying print u'ThisTextIsBr\xf8ken' in a python shell.

Your confusion is merely about how python represents unicode strings that are wrapped in another object. In this case your rows each represent a tuple of columns.

You can verify this by adjusting your code to print the actual unicode string rather than the tuple containing it.

# -*- coding: UTF-8 -*-
import pymysql
db = pymysql.connect(
 host="localhost",
 user="root",
 password="XXXXXXXX",
 db="pythonconnectiontest", 
 charset="utf8"
)
cursor = db.cursor()
cursor.execute("SELECT Username FROM Account")
numrows = cursor.rowcount 
for i in range (numrows):
 row = cursor.fetchone()
 print row[0]

This should now output the expected strings.

default

AltStyle によって変換されたページ (->オリジナル) /