Practice Project: Updating the CodeSkulptor Docs
debug了好久的我实在是太菜了..
"""
Week 4 practice project template for Python Data Representation
Update syntax for print in CodeSkulptor Docs
from "print ..." syntax in Python 2 to "print(...)" syntax for Python 3
"""
# HTML tags that bounds example code
PREFIX = "<pre class='cm'>"
POSTFIX = "</pre>"
PRINT = "print"
def update_line(line):
"""
Takes a string line representing a single line of code
and returns a string with print updated
"""
#如果行内容中找不到print直接返回,找到print先存留前面的缩进内容
if line.find(PRINT)!=-1:
first_part = line[0:line.find("print")]
else:
return line
# Strip left white space using built-in string method lstrip()
string = line.lstrip(" ")
# If line is print stat