xiaxia

第一个python程序

最近在玩pytho(呵呵.NET好久没用啦),好啦,先看看这段程序吧:

1.#!d:\Python24\python.exe
2.# Fig. 6.3: fig06_03.py
3.# Displays the current date and time in a Web browser.
4.
5.import time
6.
7.def printHeader( title ):
8.   print """Content-type: text/html
9.
10.<?xml version = "1.0" encoding = "UTF-8"?>    
11.<!DOCTYPE html PUBLIC
12.  "-//W3C//DTD XHTML 1.0 Strict//EN"
13.   "DTD/xhtml1-strict.dtd">
14.<html xmlns = "http://www.w3.org/1999/xhtml">
15.<head><title>%s</title></head>
16.
17.<body>
""" % title
18.
19.printHeader( "Current date and time" )
20.print "<p>" + time.ctime( time.time() + "</p>"
21.print "</body></html>"

 

程序很简单,以下是我的一些见解:
1.第一行是一个预编译指令,指定了python解释器在服务器上的位置.
2.第五行导入了一个time模块.
3.7-17行定义printHeader函数,作用是向IE上输出一些html的标记语言吧!
4.%S应该是一个形式参数的符号,%title可以说是一个实参.代入%S.按理可以有更多的%S,只要一一对应就OK啦.(应该是这样吧.python的语法我还没有详细看过.)
5.19是调用函数printHeader
6.20是调用time模块中的两个函数以打印当前时间,其中函数time.time返回一个浮点数
7.21向IE输出html的结束标记

 

posted on 2006-09-01 10:24  Array  阅读(252)  评论(0编辑  收藏  举报

导航