六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 49|回复: 0

builddialectexamples.py源代码分析

[复制链接]

升级  32.6%

213

主题

213

主题

213

主题

进士

Rank: 4

积分
663
 楼主| 发表于 2013-1-15 02:55:27 | 显示全部楼层 |阅读模式
<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>
"""Build examples of output of dialect module
This script is used during the build process of "Dive Into Python"
(http://diveintopython.org/) to create examples of the output of the
code in chapter 4 (dialect.py and BaseHTMLProcessor.py).
It takes one argument, the source HTML file to translate. It outputs
chef.html, fudd.html, and olde.html in the same directory as the source.
Safe to run more than once. Output files are silently overridden if
they already exist.
"""
__author__ = "Mark Pilgrim (mark@diveintopython.org)"
__version__ = "$Revision: 1.2 $"
__date__ = "$Date: 2004/05/05 21:57:19 $"
__copyright__ = "Copyright (c) 2001 Mark Pilgrim"
__license__ = "Python"
import dialect
import sys, os
%导入三个库文件
def translateAndWrite(filename, dialectname):
targetfilename = os.path.join(os.path.split(filename)[0], "%s.html" % dialectname)
%产生一个filename同目录的文件dialectname
fsock = open(targetfilename, "wb")
%打开该文件
fsock.write(dialect.translate(filename, dialectname))
%dialect.translate的作用是定义一个别名文件,然后将filename的内容完全写入dialectname
fsock.close()
%关闭文件操作符
if __name__ == "__main__":
filename = sys.argv[1]
%通过命令行参数获取filename
for dialectname in ("chef", "fudd", "olde"):
translateAndWrite(filename, dialectname)
%调用用户自定义的函数,完成复制文件的操作
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表