Python Forum
Python error: TypeError: expected string or buffer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python error: TypeError: expected string or buffer
#1
Hi all,

I am sorry for making another post 3 times in a week, but I am almost complete my project. I have converted from time.struct_time to datetime object. Now I would like to convert it back to time.struct_time object after I have added to the next day date.

When I try this:

    half_hour_date = '23/02/2018 23:00PM'
    epg_time_1 = time.strptime(half_hour_date, '%d/%m/%Y %I:%M%p')
    
    #convert from time_struct_time object to datetime
    date_format = datetime.datetime.fromtimestamp(time.mktime(epg_time_1))
    half_hour = date_format + datetime.timedelta(days = self.program_day)
    
    #convert from datetime to time_struct_time object
    epg_time_1 = time.strptime(half_hour, '%d/%m/%Y %I:%M%p')
It give me an error: TypeError: expected string or buffer

The error are highlight on this line:

epg_time_1 = time.strptime(half_hour, '%d/%m/%Y %I:%M%p')
Here is the datetime object for half_hour:
2018-02-23 23:00:00
I don't have a clue what to do as I don't know how to fix it. What I am trying to do is to get the day, month, year, 12 hours time, minutes with PM to make it to show like "23/02/2018 23:00PM" from variable called half_hour

Can you please help me with how we can solve the error to allow me to convert it back to time.struct_time object?

Thanks in advance
Reply
#2
You should look at that link I gave you before: https://pymotw.com/3/datetime/
He does all sorts of date manipulations
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  error in class: TypeError: 'str' object is not callable akbarza 2 512 Dec-30-2023, 04:35 PM
Last Post: deanhystad
  boto3 - Error - TypeError: string indices must be integers kpatil 7 1,253 Jun-09-2023, 06:56 PM
Last Post: kpatil
  "TypeError: string indices must be integers, not 'str'" while not using any indices bul1t 2 2,034 Feb-11-2023, 07:03 PM
Last Post: deanhystad
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 1,939 Oct-17-2022, 06:29 PM
Last Post: paulo79
  TypeError: string indices must be integers JonWayn 12 3,393 Aug-31-2022, 03:29 PM
Last Post: deanhystad
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,872 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  Read buffer from bluetooth frohr 2 2,137 Jun-01-2022, 01:31 PM
Last Post: frohr
  "<class 'typeerror'>: don't know how to convert" error GiggsB 3 3,355 Feb-28-2022, 06:45 PM
Last Post: GiggsB
  TypeError: not enough arguments for format string MaartenRo 6 2,929 Jan-09-2022, 06:46 PM
Last Post: ibreeden
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,114 Sep-04-2021, 09:16 PM
Last Post: eddywinch82

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020