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


Groups > comp.lang.python > #98813

Re: Problems using struct pack/unpack in files, and reading them.

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Problems using struct pack/unpack in files, and reading them.
Date Sat, 14 Nov 2015 08:43:13 -0700
Lines 38
Message-ID <mailman.329.1447515842.16136.python-list@python.org> (permalink)
References <20151113192045.GA9913@z-sverige.nu> <CALwzidknLk3w8NWJqhYXjCFy4uBm79dxhBn=oaXCtxfJu-d-_g@mail.gmail.com> <mailman.310.1447454532.16136.python-list@python.org> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <mailman.314.1447470111.16136.python-list@python.org> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de VAO3L/CkVXopUHvVgHr79gtSzIJV3s3YcmgXFcLrya1w==
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'received:209.85.223': 0.03; 'float': 0.05; 'that?': 0.05; 'javascript,': 0.07; 'seemed': 0.07; 'minus': 0.09; 'operator,': 0.09; 'stealing': 0.09; 'subject:files': 0.09; 'subject:using': 0.09; "they've": 0.09; 'way:': 0.09; 'python': 0.10; 'argument': 0.15; '+feature': 0.16; 'hypothetical': 0.16; 'negates': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'remembered': 0.16; 'something.': 0.16; 'subject:Problems': 0.16; 'sure.': 0.16; 'unary': 0.16; 'wrote:': 0.16; '2015': 0.20; 'strip': 0.22; 'symbolic': 0.22; 'code,': 0.23; 'bit': 0.23; 'header:In-Reply- To:1': 0.24; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'turns': 0.27; 'idea': 0.28; '13,': 0.29; 'decimal': 0.29; 'initiated': 0.29; 'operators': 0.29; 'perl': 0.29; 'convert': 0.29; "i'm": 0.30; 'subject:/': 0.30; 'code': 0.30; 'e.g.': 0.30; 'somebody': 0.30; 'regardless': 0.31; 'probably': 0.31; "d'aprano": 0.33; 'int': 0.33; 'steven': 0.33; 'though.': 0.33; 'values.': 0.33; 'received:google.com': 0.35; 'nov': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'needed': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'expect': 0.37; 'received:209': 0.38; 'anything': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'software': 0.40; 'ever': 0.60; 'real': 0.62; 'skip:n 10': 0.62; 'number:': 0.69; 'dsl': 0.84; 'maths': 0.84; 'subject:pack': 0.84; 'to:name:python': 0.84; 'imagine': 0.96
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=AeDUznrdCuXVeU8cD80AnY9U+DzZFVfo2ahLXwlphLA=; b=bmHRsoPCscGBIxpIxyd4M6WCFDFHe/6rrKcjd+R9K+cMlGRh2CbLbFXQcwR8JrnXi/ M6h3hW/0tN9q2uab714jPxyLowD6QreAA6owWLmLQRooyJ9B+WcBJ3c4tV0r+BBe8mbh oSQ0bNajUAXWr3SMBGjclYyiCbE37udLdtZhAkPoCI32Kv/DcP8p9RUfVVXqTROHSVRh mhh6DF/Y0w0BpobpaIDrnj2NWcBghcT7kgQkyKhC1bq7m25qeScIKujOzrCToF0tu0vA Z3ViuKi9kqslBbyVDJYkPMV+oMx807ucecqamGPizrSW+MnMoCuFGkeeWh15srXMROl6 UkKw==
X-Received by 10.107.19.12 with SMTP id b12mr29221613ioj.11.1447515834096; Sat, 14 Nov 2015 07:43:54 -0800 (PST)
In-Reply-To <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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:98813

Show key headers only | View raw


On Fri, Nov 13, 2015 at 10:40 PM, Steven D'Aprano <steve@pearwood.info> wrote:
> Python has operator overloading, so it can be anything you want it to be.
> E.g. you might have a DSL where +feature turns something on and -feature
> turns it off.

By that argument we should also have operators ~, !, $, \, ? because
some hypothetical DSL might someday want to use them for something.

> Decimal uses it to force the current precision and rounding, regardless of
> what the number was initiated to:
>
> Counter uses it to strip zero and negative counts:
>
> I would expect that symbolic maths software like Sympy probably has use of a
> unary plus operator, but I'm not sure.

Unary plus as normalization does not strike me as being very
intuitive. I never would have known about any of these if I hadn't
read the Counter case in the docs, and then I only remembered it
because it because it seemed janky. Unary minus on Counters is even
weirder, by the way: it first negates the signs of all the values, and
*then* normalizes by removing non-positive values. Who has ever needed
that?

For somebody reading one of these uses of unary plus in real code, I
imagine it would be a bit of a WTF moment if it's the first time
they've encountered it. I don't recall ever seeing any code that
actually used this, though.

> I might consider stealing an idea from Perl and Javascript, and have unary
> plus convert strings to a number:
>
> +"123"
> => returns int 123
> +"1.23"
> => returns float 1.23

Eww.

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


Thread

Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-14 09:42 +1100
  Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-14 13:40 +1100
    Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-14 14:01 +1100
      Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-14 16:40 +1100
        Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-14 08:43 -0700
          Re: Problems using struct pack/unpack in files, and reading them. Marko Rauhamaa <marko@pacujo.net> - 2015-11-14 18:52 +0200
            Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-15 04:04 +1100
              Re: Problems using struct pack/unpack in files, and reading them. Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-11-16 19:19 +1300
            Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-14 10:04 -0700
              Re: Problems using struct pack/unpack in files, and reading them. Marko Rauhamaa <marko@pacujo.net> - 2015-11-14 23:53 +0200
              Re: Problems using struct pack/unpack in files, and reading them. Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-11-16 19:15 +1300
                Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-16 23:11 +1100
                Re: Problems using struct pack/unpack in files, and reading them. Dave Farrance <df@see.replyto.invalid> - 2015-11-17 09:54 +0000
            Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-14 10:13 -0700
            Re: Problems using struct pack/unpack in files, and reading them. Random832 <random832@fastmail.com> - 2015-11-14 17:53 -0500
              Re: Problems using struct pack/unpack in files, and reading them. Marko Rauhamaa <marko@pacujo.net> - 2015-11-15 02:12 +0200
              Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-15 12:14 +1100
                Re: Problems using struct pack/unpack in files, and reading them. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-15 11:09 -0500
                Re: Problems using struct pack/unpack in files, and reading them. Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-11-16 19:11 +1300
            Re: Problems using struct pack/unpack in files, and reading them. MRAB <python@mrabarnett.plus.com> - 2015-11-15 00:49 +0000
          Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-15 13:08 +1100
            Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-15 13:23 +1100
              Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-17 00:17 +1100
                Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-17 00:27 +1100
        Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-15 03:59 +1100
    Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-13 20:45 -0700
    Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-13 20:48 -0700
    Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-14 14:56 +1100
    Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-14 14:57 +1100

csiph-web