Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: =?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?= Newsgroups: comp.lang.python Subject: timedelta and float multiplication in python 2 Date: Thu, 11 Feb 2016 11:39:25 +0100 Lines: 29 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de sVjw/X+qFJ90/lPY0UaELABXEiCO0hXEprVgo4zypgAg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'operand': 0.07; 'subject:skip:m 10': 0.09; 'typeerror:': 0.09; 'example:': 0.10; 'python': 0.10; 'subject:python': 0.14; 'received:io': 0.16; 'received:psf.io': 0.16; 'seconds,': 0.16; 'skip:d 60': 0.16; 'unsupported': 0.16; '>>>': 0.20; '"",': 0.22; 'this:': 0.23; 'thanks,': 0.24; '(most': 0.24; 'workaround': 0.29; 'checked': 0.31; 'implement': 0.32; 'point': 0.33; 'problem': 0.33; 'traceback': 0.33; "skip:' 20": 0.34; 'file': 0.34; 'this?': 0.34; 'skip:d 20': 0.34; 'could': 0.35; 'something': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'two': 0.37; 'mean': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'determine': 0.61; 'charset:iso-8859-2': 0.64; 'between': 0.65; 'today': 0.65; 'here': 0.66; 'type(s)': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopzeus.com; s=shopzeus_com; t=1455187163; bh=IBJ2nSlsI8/1WrF7VgrKeMH5b6c+5frrcmaLKHT1CzY=; h=To:From:Subject:Date:From; b=m6Z/gVlkcK+K0t9gAxAOEcjimjMzc4C2KCPev4fisRWOdkF8XL2+4gXEglczm3TEd Sq6xhjnWCbndCpNe0TVxj9j3v93iZ6/SqeCgNODaIut5yH2KSdc7YsFoHzAXb1zOcs X9AL5WQEsH+I7kCCevN0A+F8W6fYeZHNsup9SQCjWcPdwAt2zskkWDrPmh3Qri9qY8 8OnXDx2WgyZ9AxsUQesaqw1n5SvLN4QYldGKyny9rpccKieRBjc0nqedY1Qwi+VQwE bntKICLrqC4IgZex9U3LhDyy4sbPvDpDD/JTZ1sklDoik32flacVWvW5MzKEbt+sBu kCTT0/xRUkg8g== X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:102799 I ran into a problem today where I had to determine the mean point between two datetimes. Here is an example: >>> start =3D datetime.datetime(2016,2,11) >>> stop =3D datetime.datetime.now() >>> mean =3D start + (stop-start)*0.5 Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for *: 'datetime.timedelta' and 'float' A workaround could be something like this: >>> start + datetime.timedelta(seconds=3D0.5*((stop-start).total_seconds(= ))) datetime.datetime(2016, 2, 11, 5, 45, 45, 818009) Interesting thing is that total_seconds() already returns fractions of seconds, so it would be almost trivial to implement timedelta multiplication with floats. I have checked and it does work with Python 3. But it does not work with Python 2 - is there a good reason for this? Thanks, Laszlo