简体   繁体   中英

descriptor 'time' of 'datetime.datetime' object needs an argument

I have a file sorted per date / time in csv form, eg below, upon which I am making calculations. I want my code to cease calcs for that day once a certain time has passed. eg, no more calc if Time > 20:00. the time every day does not change. Data example:

Date        Time        Open    High    Low    Close    Volume
02/01/2015  14:30:00    111.39  111.44  111.2   111.24  707185
02/01/2015  14:31:00    111.24  111.3   111.14  111.3   286506

I have tried to define an endTime, then I say when time > endTime... suggestions appreciated..

endTime = datetime(int(datetime.now()), int(datetime.now()), int(datetime.now()), 15, 30, 00)
TypeError: int() argument must be a string or a number, not 'datetime.datetime'

endTime = datetime.time(hour=20, minute=00, second=00)
TypeError: descriptor 'time' of 'datetime.datetime' object needs an argumen

class datetime.datetime

A combination of a date and a time. Attributes: year, month, day, hour, minute, second, microsecond, and tzinfo.

>>> import datetime

>>> endDateTime = datetime.datetime(2015, 2, 1, 14, 30, 00)
>>> endDate = datetime.date(2015, 2, 1)
>>> endTime = datetime.time(14, 30, 00)

>>> now = datetime.datetime.now()
>>> endTime = datetime.datetime(now.year, now.month, now.day, now.hour, now.minute, now.second)

I think datetime.now() returns a datetime whereas you want an int.

eg. datetime.now().hour.

https://docs.python.org/2/library/datetime.html

import datetime now = datetime.datetime.now().time() type(now.hour)

>>> int

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM