Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #67592
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <cameron@cskk.homeip.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'permitted': 0.07; 'keys,': 0.09; 'slices': 0.09; 'wrapper': 0.09; 'def': 0.12; 'aggregation,': 0.16; 'behave': 0.16; 'copying.': 0.16; 'dict': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'overridden': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'redundant': 0.16; 'rhodes': 0.16; 'simpson': 0.16; 'storing': 0.16; 'subclass': 0.16; 'subclassing': 0.16; 'writable': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'cheers,': 0.24; 'performing': 0.26; 'least': 0.26; 'world,': 0.26; 'header:In- Reply-To:1': 0.27; 'idea': 0.28; 'leave': 0.29; 'have,': 0.30; 'fast.': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'subject:from': 0.34; 'but': 0.35; 'there': 0.35; 'received:com.au': 0.36; 'skip:> 10': 0.36; 'doing': 0.36; 'implement': 0.38; 'received:211': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'then,': 0.60; 'simply': 0.61; 'simple': 0.61; 'first': 0.61; 'content-disposition:inline': 0.62; 'subject:get': 0.81; 'idiots': 0.84; 'julie': 0.84; 'thing...': 0.84 |
| Date | Tue, 4 Mar 2014 09:02:07 +1100 |
| From | Cameron Simpson <cs@zip.com.au> |
| To | python-list@python.org |
| Subject | Re: how to get bytes from bytearray without copying |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Disposition | inline |
| Content-Transfer-Encoding | 8bit |
| In-Reply-To | <lf1dlq$94o$1@ger.gmane.org> |
| User-Agent | Mutt/1.5.21 (2010-09-15) |
| References | <lf1dlq$94o$1@ger.gmane.org> |
| X-Optus-CM-Score | 0 |
| X-Optus-CM-Analysis | v=2.1 cv=Wu4Sb7vv c=1 sm=1 tr=0 a=YuQlxtEQCowy2cfE5kc7TA==:117 a=YuQlxtEQCowy2cfE5kc7TA==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=LcaDllckn3IA:10 a=GCYxRCg_PokA:10 a=IkcTkHD0fZMA:10 a=vrnE16BAAAAA:8 a=pGLkceISAAAA:8 a=LvLpXEYgAAAA:8 a=gsBrBudCXCulw6qD__4A:9 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10 a=WjE-N-J3fjQA:10 |
| 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 | <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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7665.1393884137.18130.python-list@python.org> (permalink) |
| Lines | 32 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1393884137 news.xs4all.nl 2916 [2001:888:2000:d::a6]:39689 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:67592 |
Show key headers only | View raw
On 03Mar2014 09:15, Juraj Ivančić <juraj.ivancic@gmail.com> wrote:
> On 3.3.2014. 1:44, Cameron Simpson wrote:
> >>ValueError: cannot hash writable memoryview object
> >
> >Have you considered subclassing memoryview and giving the subclass
> >a __hash__ method?
>
> I have, and then, when I failed to subclass it, I considered doing
> aggregation, and make it behave byte-like. But how to implement the
> overridden __hash__ method? It will still require at least *some*
> redundant copying. And there is the slicing thing... the whole idea
> started to feel like I was performing tonsillectomy through the anal
> cavity.
Write a wrapper class instead and use:
def __hash__(self):
return id(self)
Simple and fast. Unless you need slices with the same content to
hash the same (eg storing them as dict keys, or in sets).
And alternative would be a simple hash of the first few bytes in
whatever slice you had.
Cheers,
--
Cameron Simpson <cs@zip.com.au>
Why is it so hard for people to simply leave people alone? But, the answer
comes to me: they are idiots and in a perfect world, I would be permitted to
kill them all. - Julie Rhodes <jk.rhodes@asacomp.com>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: how to get bytes from bytearray without copying Cameron Simpson <cs@zip.com.au> - 2014-03-04 09:02 +1100
csiph-web