Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61330
| Date | 2013-12-08 16:18 -0600 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: Eliminate "extra" variable |
| References | (6 earlier) <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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3745.1386541065.18130.python-list@python.org> (permalink) |
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),)
Note that it returns a datetime.date, the same as it was defined.
-tkc
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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