Re: Unconverted data remains

Discussion in 'Python' started by Peter Otten, Nov 8, 2012.

  1. Peter Otten

    Peter Otten Guest

    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]
     
    Peter Otten, Nov 8, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vMike
    Replies:
    1
    Views:
    481
    Natty Gur
    Aug 26, 2003
  2. vMike
    Replies:
    1
    Views:
    354
    Natty Gur
    Aug 26, 2003
  3. Chris
    Replies:
    1
    Views:
    311
    bruce barker
    Apr 12, 2004
  4. \Rob\
    Replies:
    0
    Views:
    424
    \Rob\
    May 10, 2004
  5. MRAB

    Re: Unconverted data remains

    MRAB, Nov 8, 2012, in forum: Python
    Replies:
    0
    Views:
    214
Loading...

Share This Page