我當前正試圖將datetime.date對象與datetime.time對象組合起來,以獲取生成的datetime.datetime樣式對象。將datetime.date對象與datetime.time對象結合時出錯
我運行一個SQL查詢,並通過執行以下分析結果:
import sqlite3
import time
import datetime
conn = sqlite3.connect('stu.sqlite3', detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
cur = conn.cursor()
cur.execute('SELECT intra_day.date, intra_day.time, intra_day.price, closing_price.date, closing_price.cprice FROM intra_day, closing_price WHERE intra_day.date = closing_price.date')
for row in cur:
date_intra, time_intra, price_intra, cp_date, cprice = (row[0], row[1], float(row[2]), row[3], float(row[4]))
date_intra = datetime.datetime.strptime(date_intra, '%d/%m/%Y %H:%M:%S').date()
time_intra = datetime.datetime.strptime(time_intra, '%H:%M:%S').time()
cp_date = datetime.datetime.strptime(cp_date, '%d/%m/%Y %H:%M:%S').date()
一旦已經跑了,我跑在IDLE我得到的類型和打印檢查以下內容:
type(date_intra)
Out[2]: datetime.date
type(time_intra)
Out[3]: datetime.time
type(cp_date)
Out[4]: datetime.date
print date_intra, time_intra, price_intra, cp_date, cprice
2008-07-07 05:40:00 1265.5 2008-07-07 1251.75
date_intra, time_intra, price_intra, cp_date, cprice
Out[13]:
(datetime.date(2008, 7, 7),
datetime.time(5, 40),
1265.5,
datetime.date(2008, 7, 7),
1251.75)
所以從這一點,這一切看起來我應該能夠使用:
datetime.datetime.combine(date_intra(), time_intra())
的日期對象結合和時間對象,但我得到了以下錯誤:
TypeError: 'datetime.date' object is not callable
因爲我不是偉大與Python我也試過:
datetime.datetime.combine(datetime.date(date_intra), datetime.time(time_intra))
但得到以下錯誤:
TypeError: an integer is required
莫非
任何人都指出我做錯了什麼,或許糾正了我?
一旦我結合了這兩個(date_intra和time_intra),我希望結合cp_date和time_intra。
您是否試過'datetime.datetime.combine(date_intra,time_intra)'? – jonrsharpe