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


Groups > comp.lang.python > #61939

Re: Eliminate "extra" variable

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ikorot01@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'string': 0.09; 'converted': 0.09; 'subject:extra': 0.09; 'python': 0.11; 'bug': 0.12; 'wrote': 0.14; '-tkc': 0.16; 'command.': 0.16; 'debugger.': 0.16; 'defined.': 0.16; 'igor': 0.16; 'res': 0.16; 'skip:d 60': 0.16; 'sqlite': 0.16; 'subject:variable': 0.16; 'tim,': 0.16; 'wrote:': 0.18; 'module': 0.19; '>>>': 0.22; 'select': 0.22; 'import': 0.22; 'print': 0.22; 'string,': 0.24; 'purposes': 0.26; 'this:': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; "i'm": 0.30; 'url:mailman': 0.30; '>>>>': 0.31; 'chase': 0.31; 'probably': 0.32; 'text': 0.33; 'url:python': 0.33; 'running': 0.33; 'guess': 0.33; 'table': 0.34; 'maybe': 0.34; 'skip:d 20': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'dates': 0.36; 'processed': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'should': 0.36; 'so,': 0.37; 'thank': 0.38; 'confirmed': 0.38; 'window': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; '12,': 0.39; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'url:mail': 0.40; 'engines': 0.60; 'tell': 0.60; 'you.': 0.62; 'today': 0.64; 'kept': 0.65; 'between': 0.67; 'legal': 0.71; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=i0TPDXQ5fo21n5iJYfCKEQvjlDroOnYUzNpLhuCaa/U=; b=UdzOPcWPcLMXpHMPFQVGf/B6qztBwkM4FzhMk0TYAr1f8DHfK/o6yDW7vW4UZiEP46 qFNEu8zeJ+aNvFD6TiaPOQDJ8YclHQ2eJiu6bz7CuLbu/0+wF0+fDsHCOusHIz11n05E liIy+SuEkd1rJlUJuxJ33JxRIokXjQ3NszgqL9PMu11J80Ei7HpItA3B3uoZ92Fjw7c0 69q/1kRm1DfNxhLZI0M2OW8tQ5ZYDd84vlP1SB5Cvug4YmUFVFiqHR0hYIA6atFMGwl3 QRAS07tkS2wcOX2TVdRVe/yKA7MAkgbIvbCO8kLpv5CssFnsKHgFmPFgeT7dhfG31zOY ZpJQ==
MIME-Version 1.0
X-Received by 10.220.184.70 with SMTP id cj6mr1328064vcb.23.1387093798102; Sat, 14 Dec 2013 23:49:58 -0800 (PST)
In-Reply-To <20131208161858.1365f2d7@bigbox.christie.dr>
References <CA+FnnTzDjRzU65+VWnOwxfVR9FGMDgHLLmLEDOoGE0BMCptzEw@mail.gmail.com> <52A25D94.9040404@islandtraining.com> <CA+FnnTxxJc2J1SF0UHXo1DkZPdN0W5iWhOgBYzfbW1T0GtaSgg@mail.gmail.com> <CA+FnnTzBYp5Fvy1ohCySLitbL21+hHdfur9=oF4TM+Skeu-XJw@mail.gmail.com> <CA+FnnTzkHYNN_rgLaaXwvod9qGhetXRy+3v96+5+wEyhCq0LwA@mail.gmail.com> <CA+FnnTwZ3aF++ZzaAJzG0Y98usfLTge0KTzj14LfqDgh1OnsZQ@mail.gmail.com> <20131208125823.241112db@bigbox.christie.dr> <mailman.3738.1386529877.18130.python-list@python.org> <roy-E243A9.15072508122013@news.panix.com> <CA+FnnTyZzrhwkLvsY0EdvXD_PoTWK45C0=peWGWtse1uEwJC=Q@mail.gmail.com> <CA+FnnTwSKYs-RAqVT-fZpotte30+xC-oUx-qnidw_qA=uv+KSA@mail.gmail.com> <20131208161858.1365f2d7@bigbox.christie.dr>
Date Sat, 14 Dec 2013 23:49:58 -0800
Subject Re: Eliminate "extra" variable
From Igor Korot <ikorot01@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
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.4138.1387093806.18130.python-list@python.org> (permalink)
Lines 67
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1387093806 news.xs4all.nl 2873 [2001:888:2000:d::a6]:36021
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:61939

Show key headers only | View raw


Tim,

On Sun, Dec 8, 2013 at 2:18 PM, Tim Chase <python.list@tim.thechases.com> wrote:
> On 2013-12-08 12:58, Igor Korot wrote:
>> Also, the data comes from either SQLite or mySQL and so to eliminate
>> the difference between those engines dates are processed as strings
>> and converted to dates for the calculation purposes only.
>> Maybe I will need to refactor SQLite processing to get the dates as
>> dates and not a string, but that's probably for the future. so that
>> dates will be kept as the datetime type until the end of the
>> function. As I wrote the dates will be used as the text for the
>> plotting window axis labels and as the labels they should come out
>> as strings, hence the conversion.
>
> Sqlite can do this automatically if you tell it to upon connecting:
>
>>>> import sqlite3
>>>> conn = sqlite3.connect('x.sqlite',
> ...    detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
>>>> cur.execute("create table foo (s date);")
> <sqlite3.Cursor object at 0x7f7f31665570>
>>>> import datetime
>>>> today = datetime.date.today()
>>>> cur.execute("insert into foo(s) values (?)", (today,))
> <sqlite3.Cursor object at 0x7f7f31665570>
>>>> cur.execute("select * from foo")
> <sqlite3.Cursor object at 0x7f7f31665570>
>>>> r = cur.fetchone()
>>>> print r
> (datetime.date(2013, 12, 8),)

Interesting.
I'm using datetime rather than the date type for CREATE TABLE() command.
And when running SELECT I still see the b'1998-08-05 23:12:12' string
representation when running my program under debugger.

And it is confirmed by running this:

>>> cur.execute("CREATE TABLE foo(bar datetime);")
<sqlite3.Cursor object at 0x00E1E6A0>
>>> import datetime
>>> today = datetime.date.today()
>>> cur.execute("insert into foo(bar) values (?)", (today,))
<sqlite3.Cursor object at 0x00E1E6A0>
>>> cur.execute("select * from foo")
<sqlite3.Cursor object at 0x00E1E6A0>
>>> res = cur.fetchall()
>>> print res
[(u'2013-12-14',)]
>>>

So, I guess this is a bug in the sqlite3 python module as datetime is
legal data type on the DB engine.

Thank you.

>
>
> Note that it returns a datetime.date, the same as it was defined.
>
> -tkc
>
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list

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


Thread

Re: Eliminate "extra" variable Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-08 19:10 +0000
  Re: Eliminate "extra" variable Roy Smith <roy@panix.com> - 2013-12-08 15:07 -0500
    Fwd: Eliminate "extra" variable Igor Korot <ikorot01@gmail.com> - 2013-12-08 12:58 -0800
    Re: Eliminate "extra" variable Tim Chase <python.list@tim.thechases.com> - 2013-12-08 16:18 -0600
    Re: Fwd: Eliminate "extra" variable Dave Angel <davea@davea.name> - 2013-12-08 17:36 -0500
    Re: Eliminate "extra" variable Igor Korot <ikorot01@gmail.com> - 2013-12-14 23:49 -0800
    Re: Eliminate "extra" variable Tim Chase <python.list@tim.thechases.com> - 2013-12-15 06:17 -0600
    Re: Eliminate "extra" variable Tim Chase <python.list@tim.thechases.com> - 2013-12-15 06:29 -0600
    Re: Eliminate "extra" variable Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-15 12:08 -0500
    Re: Eliminate "extra" variable Igor Korot <ikorot01@gmail.com> - 2013-12-15 14:46 -0800
    Re: Eliminate "extra" variable MRAB <python@mrabarnett.plus.com> - 2013-12-16 00:58 +0000
    Re: Eliminate "extra" variable Igor Korot <ikorot01@gmail.com> - 2013-12-15 18:43 -0800
    Re: Eliminate "extra" variable Dave Angel <davea@davea.name> - 2013-12-15 21:58 -0500
    Re: Eliminate "extra" variable Chris Angelico <rosuav@gmail.com> - 2013-12-16 13:57 +1100
    Re: Eliminate "extra" variable Igor Korot <ikorot01@gmail.com> - 2013-12-15 20:24 -0800

csiph-web