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程序。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在java中将字符串转换为音频输入   java如何使用Spring Boot RestTemplate解组json列表   计算机上C++ OpenCV项目转换为OpenCV Android的java步骤   Java Spring Telegraf数据表不工作   openurlconnection与connect之间的java差异?   java Solr字段搜索、通配符和转义字符   java如何使用DLFolderLocalServiceUtil类的getFolders()方法?   尝试用Java编写文件   java连续双缓冲解决方案不起作用   两个数组的Java乘积   java Jackson,如何正确编写自定义反序列化程序   java将布尔标志按一定顺序排列以获得更好的性能是否有意义   java Vaadin无缓冲网格无法关闭   java在MySQL中以同一用户身份同时从不同客户端登录安全吗?   java如何使用安卓asynchttp库   java无法在Android中使用AlarmManager停止服务   java在Hibernate的XML配置文件中指定默认值   Spring启动应用程序中的java内存SQLITE不工作   Java代码无法写入文本文件,