How do I make a Brainfuck interpreter in Python?
Brainfuck is an esoteric programming language that consists of only eight commands, each represented by a single character. Here's one way to write a Brainfuck interpreter in Python:

'''python
def brainfuck(code, input_str):
    code_ptr = 0
    data_ptr = 0
    data = [0] * 30000
    input_ptr = 0
    output = 

    while code_ptr < len(code):
        char = code[code_ptr]

        if char == >:
            data_ptr += 1
        elif char == <:
            data_ptr -= 1
        elif char == +:
            data[data_ptr] += 1
        elif char == -:
            data[data_ptr] -= 1
        elif char == .:
            output += chr(data[data_ptr])
        elif char == ,:
            if input_ptr < len(input_str):
                data[data_ptr] = ord(input_str[input_ptr])
                input_ptr += 1
        elif char == [ and data[data_ptr] == 0:
            loop_count = 1
            while loop_count > 0:
                code_ptr += 1
                if code[code_ptr] == [:
                    loop_count += 1
                elif code[code_ptr] == ]:
                    loop_count -= 1
        elif char == ] and data[data_ptr] != 0:
            loop_count = 1
            while loop_count > 0:
                code_ptr -= 1
                if code[code_ptr] == [:
                    loop_count -= 1
                elif code[code_ptr] == ]:
                    loop_count += 1
        code_ptr += 1

    return output
'''

You can use this interpreter by calling the brainfuck function with the Brainfuck code and the input string as arguments. For example:

'''python
code = ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
input_str = 

output = brainfuck(code, input_str)
print(output)
'''

This should produce the output Hello World!
It works.  Can you please rewrite, but add comments for each of the bf operators.  Also, if the bf code has an infinite loop then it will never return and print.  Can you please add the print into the loop so it'll prints as it goes?