Colab

import re

body = """
print       "hello", "world"
for i in range(10):
    print i
    
"""

regex = r"([ \t]*)print[ \t]+(.*)"
replacement = r"\1print(\2)"

result = re.sub(regex, replacement, body)
print(result)


print("hello", "world")
for i in range(10):
    print(i)
    

print(body)


print "hello", "world"
for i in range(10):
    print i