Skip to content

Instantly share code, notes, and snippets.

@crmccreary
Created October 19, 2018 15:22
Show Gist options
  • Save crmccreary/6ecc52bd385fe47e0800c190fc6a0f5b to your computer and use it in GitHub Desktop.
Save crmccreary/6ecc52bd385fe47e0800c190fc6a0f5b to your computer and use it in GitHub Desktop.
Converts python 2 print to python 3 print()
def convert_print(text):
index_of_print = text.find(PRINT)
if index_of_print != -1:
# find the argument of print
arg = text[index_of_print + len(PRINT):]
# Strip left white space using built-in string method lstrip()
# If line is print statement, use the format() method to add insert parentheses
return 'print({})'.format(arg.lstrip())
else:
return text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment