Created
October 19, 2018 15:22
-
-
Save crmccreary/6ecc52bd385fe47e0800c190fc6a0f5b to your computer and use it in GitHub Desktop.
Converts python 2 print to python 3 print()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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