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: 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: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> <20131208161858.1365f2d7@bigbox.christie.dr> Date: Sat, 14 Dec 2013 23:49:58 -0800 Subject: Re: Eliminate "extra" variable From: Igor Korot 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 Tim, On Sun, Dec 8, 2013 at 2:18 PM, Tim Chase 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);") > >>>> import datetime >>>> today = datetime.date.today() >>>> cur.execute("insert into foo(s) values (?)", (today,)) > >>>> cur.execute("select * from foo") > >>>> 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);") >>> import datetime >>> today = datetime.date.today() >>> cur.execute("insert into foo(bar) values (?)", (today,)) >>> cur.execute("select * from foo") >>> 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