I have a file in the following format
Summary:meeting Description:None DateStart:20100629T110000 DateEnd:20100629T120000 Time:20100805T084547Z
Summary:meeting Description:None DateStart:20100630T090000 DateEnd:20100630T100000 Time:20100805T084547Z
I need to create a function that will retrieve the “Summary” at the given “date” and “time”. For example, a function will have two arguments, a date and time, which will not be in date time formats. He should check if the date and time specified in the function argument matches between the date and time in DateStart and DateEnd in the file.
I am not sure how to get the time and date from the format indicated above [i.e. 20100629T110000]. I tried to use the following
line_time = datetime.strptime(time, "%Y%D%MT%H%M%S")where the time is "20100629T110000", but I get a lot of errors, for example, "datetime.datetime does not have the strptime attribute".
What is the correct way to perform this function, thanks in advance.
.................... EDIT ................
Here is my mistake
Python 2.4.1 (
Type "copyright", "credits" or "license()" for more information.
****************************************************************
Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer internal loopback
interface. This connection is not visible on any external
interface and no data is sent to or received from the Internet.
****************************************************************
>>>
Traceback (most recent call last):
File "C:\Python24\returnCalendarstatus", line 24, in -toplevel-
status = calendarstatus()
File "C:\Python24\returnCalendarstatus", line 16, in calendarstatus
line_time = datetime.strptime(time, "%Y%m%dT%H%M%S")
AttributeError: type object 'datetime.datetime' has no attribute 'strptime'
>>>
And here is my code
import os
import datetime
import time
from datetime import datetime
def calendarstatus():
g = open('calendaroutput.txt','r')
lines = g.readlines()
for line in lines:
line=line.strip()
info=line.split(";")
summary=info[1]
description=info[2]
time=info[5];
line_time = datetime.strptime(time, "%Y%m%dT%H%M%S")
return line_time.year
status = calendarstatus()
source
share