Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102631

Re: What's the best/neatest way to get Unicode data from a database into a grid cell?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Dietmar Schwertberger <maillist@schwertberger.de>
Newsgroups comp.lang.python
Subject Re: What's the best/neatest way to get Unicode data from a database into a grid cell?
Date Sun, 7 Feb 2016 16:06:24 +0100
Lines 29
Message-ID <mailman.74.1454861303.2317.python-list@python.org> (permalink)
References <tqljoc-nad.ln1@esprimo.zbmc.eu>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de h/+rObcjPjUNjnPG7o3TxwGs+WVvlMhQnDH1SM32kw9A==
Return-Path <maillist@schwertberger.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'modify': 0.04; 'tries': 0.05; 'except:': 0.07; 'strings.': 0.07; 'fails.': 0.09; 'other)': 0.09; 'subject:into': 0.09; 'python': 0.10; 'subject: \n ': 0.15; 'basestring):': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Unicode': 0.16; 'wrote:': 0.16; 'string,': 0.18; 'try:': 0.18; 'versions': 0.20; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'error': 0.27; 'handling': 0.27; 'switch': 0.27; 'received:192.168.10': 0.29; 'value)': 0.29; 'code:': 0.29; 'convert': 0.29; 'subject:/': 0.30; 'e.g.': 0.30; 'problem': 0.33; 'handle': 0.34; 'unicode': 0.35; 'quite': 0.35; 'something': 0.35; 'should': 0.36; 'there': 0.36; '(and': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'names': 0.38; 'data': 0.39; 'subject:from': 0.39; 'subject:the': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'course': 0.62; 'here': 0.66; 'subject:get': 0.81; 'phoenix': 0.84; 'received:192.168.0.5': 0.91
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Thunderbird/44.0
In-Reply-To <tqljoc-nad.ln1@esprimo.zbmc.eu>
X-Virus-Scanned clamav-milter 0.98.7 at mxout1
X-Virus-Status Clean
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=mailerdienst.de; s=dkim; t=1454857588; bh=M1FgHhnM2DL76tBT8s32RSK6tr4r1Mx3rpLzyRxL1NY=; h=Subject:To:References:From:Date:In-Reply-To:From; b=Xz5ju/O9MEXVEDR/A8FGeh2+uvhm1BP1gH9z+yBFxuXMpUrCOfqNINLzdPnVtn0YY C/UbuuFMKwUNjmvoq6KAGjyE0EJcRuZY5X/d1QvtSAw3enOKIwUfCc20veO07OeuqO h/yT1+VMLSU7gZdv7tFRqmrLNFCudwiAMmtExMqI=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:102631

Show key headers only | View raw


On 07.02.2016 12:19, cl@isbd.net wrote:
> However my database has quite a lot of Unicode data as there are
> French (and other) names with accents etc.  What's the right way to
> handle this reasonably neatly?  At the moment it traps an error at
> line 37:-
>      self.SetCellValue(row_num, i, str(cells[i]))
The unicode versions of wxPython should have no problems with handling 
unicode strings.
The problem that you see here is that str(...) tries to convert your 
unicode data into a non-unicode string, which of course fails.
Do something like:

value = cells[i]
if not isinstance(value, basestring):
     value = str(value)
self.SetCellValue(row_num, i, value)

Once you switch to Python 3 and Phoenix you have to modify this 
slightly, e.g. by adding this to the top of your code:

try:
     basestring
except:
     basestring = (bytes,str)


Regards,

Dietmar

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

What's the best/neatest way to get Unicode data from a database into a grid cell? cl@isbd.net - 2016-02-07 11:19 +0000
  Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Chris Angelico <rosuav@gmail.com> - 2016-02-07 22:56 +1100
    Re: What's the best/neatest way to get Unicode data from a database into a grid cell? cl@isbd.net - 2016-02-07 12:42 +0000
      Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Chris Angelico <rosuav@gmail.com> - 2016-02-08 00:11 +1100
        Re: What's the best/neatest way to get Unicode data from a database into a grid cell? cl@isbd.net - 2016-02-07 13:59 +0000
  Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Dietmar Schwertberger <maillist@schwertberger.de> - 2016-02-07 16:06 +0100
    Re: What's the best/neatest way to get Unicode data from a database into a grid cell? cl@isbd.net - 2016-02-08 10:22 +0000
      Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Chris Angelico <rosuav@gmail.com> - 2016-02-08 21:57 +1100
  Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Vlastimil Brom <vlastimil.brom@gmail.com> - 2016-02-07 19:22 +0100
    Re: What's the best/neatest way to get Unicode data from a database into a grid cell? cl@isbd.net - 2016-02-08 10:42 +0000
      Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Chris Angelico <rosuav@gmail.com> - 2016-02-08 21:55 +1100
      Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Vlastimil Brom <vlastimil.brom@gmail.com> - 2016-02-08 16:00 +0100

csiph-web