You had the right idea with the commented-out code, it just needs a little tweaking. Once you're read the BOM using the codec, it's no longer a 3-byte UTF-8 sequence or even a UTF-16 code, it's a single Unicode character U+FEFF.
if content[0] == U'\uFEFF':
content = content[1:]
Also note that the replace
function wouldn't have worked since it doesn't do an in-place replacement - it can't since strings in Python are immutable. You can assign the result back to itself. Since we know it's only a single character, I simplified it with a slice.