python的识字编程
mylit的Python项目详细描述
mylit是一个使用python编写有文化编程的简单工具。
识字的python程序只是普通的python源文件 评论。当mylit以一个可读的python程序作为输入运行时,它 创建包含注释和突出显示的源代码的HTML文件。你 可以在您认为合适的注释中使用HTML标记。
除了简单的注释外,还可以自定义html编译过程 以开始注释行。任何跟在这条线上的东西 在解析器的上下文中执行。例如,代码可以设置变量, 操作生成的html,或生成调试输出。看看我的网站 看看它能做什么。
以开头的行!完全忽略。这样,你就可以发表评论了 不打算包含在最终html文件中的内容。
下面是一个简单的示例,说明一个识字程序可能是什么样子的:
#!/usr/bin/env python #! This line is ignored, as is the previous line. #! Set the title variable of the parser: ## title = "mylit example" # <h1>A simple mylit example</h1> # This is a simple example of literate <a # href="http://www.python.org/">Python</a> programming with <a # href="http://pypi.python.org/pypi/mylit">mylit</a>. # Here we define a function that checks whether a given pair of coordinates # lies within a circle of radius <code>r</code>. def in_circle(x, y, r): # We first square both <code>x</code> and <code>y</code>, and sum them up. s = x ** 2 + y ** 2 # <p>Note how the above comment contains HTML markup. The indentation of # the highlighted Python code is unaffected by interspersed comments.</p> # Here we check whether the coordinates (<code>x</code>, <code>y</code>) # lie within a circle of radius <code>r</code>. if s < r ** 2: # Everything's okay, so we can return <code>True</code>: return True else: # We may have a problem here. Better print a warning. import warnings warnings.warn("Danger, Will Robinson!") return False # When this program is run from the command line, it performs a simple test. if __name__ == "__main__": assert in_circle(3, 4, 5.1) == True assert in_circle(3, 4, 4.9) == False
当然,mylit本身就是一个识字的python程序。