{"id":903,"date":"2014-08-31T08:51:57","date_gmt":"2014-08-31T15:51:57","guid":{"rendered":"http:\/\/somethingk.com\/main\/?p=903"},"modified":"2014-08-31T08:55:21","modified_gmt":"2014-08-31T15:55:21","slug":"python-typeerror-expected-a-character-buffer-object","status":"publish","type":"post","link":"https:\/\/somethingk.com\/main\/python-typeerror-expected-a-character-buffer-object\/","title":{"rendered":"Python TypeError: expected a character buffer object"},"content":{"rendered":"<h3>Error<\/h3>\n<p>I received the following python error:<\/p>\n<pre>TypeError: expected a character buffer object<\/pre>\n<p>The below screenshot shows my code.<\/p>\n<p><a href=\"http:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/08\/image0031.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-904\" src=\"http:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/08\/image0031.png\" alt=\"Python Error\" width=\"932\" height=\"281\" srcset=\"https:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/08\/image0031.png 932w, https:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/08\/image0031-300x90.png 300w\" sizes=\"(max-width: 932px) 100vw, 932px\" \/><\/a><\/p>\n<h3>Solution<\/h3>\n<p>I was using the <a title=\"Python String replace() Method\" href=\"http:\/\/www.tutorialspoint.com\/python\/string_replace.htm\" target=\"_blank\">replace<\/a> method, while the better method for my situation would be to use the <a title=\"Python Regular Expressions\" href=\"http:\/\/www.tutorialspoint.com\/python\/python_reg_expressions.htm\" target=\"_blank\">re.sub(patter, replace, string)<\/a> method, the new line became:<\/p>\n<pre>my_text = re.sub(comp, '#undef SEEK_SET\\n#undef SEEK_END\\n\r\n#undef SEEK_CUR\\n#include ', f)<\/pre>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Error I received the following python error: TypeError: expected a character buffer object The below screenshot shows my code. 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, &#8216;#undef SEEK_SET\\n#undef SEEK_END\\n #undef SEEK_CUR\\n#include &#8216;, f) The replace method expects [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[177,72],"tags":[309,311,310,258,312,339,259,313],"class_list":["post-903","post","type-post","status-publish","format-standard","hentry","category-development","category-python","tag-2-7","tag-buffer","tag-character","tag-error","tag-expected","tag-python","tag-solution","tag-typeerror"],"_links":{"self":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/comments?post=903"}],"version-history":[{"count":2,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/903\/revisions"}],"predecessor-version":[{"id":906,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/903\/revisions\/906"}],"wp:attachment":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/media?parent=903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/categories?post=903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/tags?post=903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}