Python TypeError: expected a character buffer object

Error

I received the following python error:

TypeError: expected a character buffer object

The below screenshot shows my code.

Python Error

Solution

I was using the replace method, while the better method for my situation would be to use the re.sub(patter, replace, string) method, the new line became:

my_text = re.sub(comp, '#undef SEEK_SET\n#undef SEEK_END\n
#undef SEEK_CUR\n#include ', f)

The replace method expects string parameters (looks for a string within a string), while I wanted to use a regular expression to search a string.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.