Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'converted': 0.09; 'subject:extra': 0.09; 'wrote': 0.14; '-tkc': 0.16; 'defined.': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'igor': 0.16; 'skip:d 60': 0.16; 'sqlite': 0.16; 'subject:variable': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'print': 0.22; 'string,': 0.24; 'purposes': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'skip:( 20': 0.30; 'probably': 0.32; 'text': 0.33; 'table': 0.34; 'maybe': 0.34; 'skip:d 20': 0.34; 'but': 0.35; 'dates': 0.36; 'processed': 0.36; 'charset:us- ascii': 0.36; 'should': 0.36; 'window': 0.38; 'to:addr:python- list': 0.38; '12,': 0.39; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'engines': 0.60; 'tell': 0.60; 'today': 0.64; 'kept': 0.65; 'between': 0.67; 'received:50.22': 0.84 Date: Sun, 8 Dec 2013 16:18:58 -0600 From: Tim Chase To: python-list@python.org Subject: Re: Eliminate "extra" variable In-Reply-To: References: <52A25D94.9040404@islandtraining.com> <20131208125823.241112db@bigbox.christie.dr> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386541065 news.xs4all.nl 2943 [2001:888:2000:d::a6]:59260 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61330 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),) Note that it returns a datetime.date, the same as it was defined. -tkc