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


Groups > comp.lang.python > #51651

Re: Problem with psycopg2, bytea, and memoryview

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'versions,': 0.07; 'imho.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'suggest': 0.14; '*why*': 0.16; 'choice,': 0.16; 'from:addr:pitrou.net': 0.16; 'from:addr:solipsis': 0.16; 'from:name:antoine pitrou': 0.16; 'message-id:@post.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Problem': 0.16; 'module': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'compare': 0.26; 'asking': 0.27; 'header:X-Complaints-To:1': 0.27; 'ideal': 0.29; "doesn't": 0.30; 'writes:': 0.31; 'anyone': 0.31; 'text': 0.33; 'url:python': 0.33; 'sense': 0.34; 'subject:with': 0.35; 'but': 0.35; 'returning': 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'example,': 0.37; 'project': 0.37; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'recent': 0.39; 'explain': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'url:3': 0.61; 'more': 0.64; 'afraid': 0.65; 'frank': 0.68; 'results': 0.69; 'url:4': 0.69; 'antoine.': 0.84; 'blob': 0.84; 'improvement': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Antoine Pitrou <solipsis@pitrou.net>
Subject Re: Problem with psycopg2, bytea, and memoryview
Date Wed, 31 Jul 2013 13:07:33 +0000 (UTC)
References <ktam8i$hj3$1@ger.gmane.org> <loom.20130731T114936-455@post.gmane.org> <ktat7p$t70$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host sea.gmane.org
User-Agent Loom/3.14 (http://gmane.org/)
X-Loom-IP 88.163.232.20 (Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.20.1375276076.1251.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375276076 news.xs4all.nl 15908 [2001:888:2000:d::a6]:49286
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51651

Show key headers only | View raw


Frank Millman <frank <at> chagford.com> writes:
> 
> Thanks for that, Antoine. It is an improvement over tobytes(), but i am 
> afraid it is still not ideal for my purposes.

I would suggest asking the psycopg2 project why they made this choice, and
if they would reconsider. Returning a memoryview doesn't make much sense IMHO.

For example, the standard sqlite3 module returns bytes for BLOB columns,
and str for TEXT columns:
http://docs.python.org/3.4/library/sqlite3.html#introduction

> Can anyone explain *why* the results do not compare equal? If I understood 
> the problem, I might be able to find a workaround.

Well, under recent Python versions, they should compare equal:

Python 3.2.3 (default, Oct 19 2012, 19:53:16) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> memoryview(b"abc") == b"abc"
True


Regards

Antoine.

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


Thread

Re: Problem with psycopg2, bytea, and memoryview Antoine Pitrou <solipsis@pitrou.net> - 2013-07-31 13:07 +0000

csiph-web