Unconverted data remains

Peter Otten __peter__ at web.de
Thu Nov 8 09:57:16 CET 2012


Nikhil Verma wrote:

> I have a list :-
>  L = ['Sunday November 11  2012 9:00pm ', 'Thursday November 15  2012
> 7:00pm ',\

[...]

>  2012 7:00pm ']

> final_event_time = [datetime.strptime(iterable, '%A %B %d %Y %I:%M%p') for
> iterable in L]
> 
> and having this error Unconverted data remains . I am trying to convert
> all these in datetime object.

Your date strings have trailing whitespace, try changing the format to

final_event_time = [datetime.strptime(s, '%A %B %d %Y %I:%M%p ') for s in L]

or apply strip to the date strings:

final_event_time = [datetime.strptime(s.strip(), '%A %B %d %Y %I:%M%p') for 
s in L]



More information about the Python-list mailing list