-
Notifications
You must be signed in to change notification settings - Fork 0
/
address_book.py
61 lines (54 loc) · 1.73 KB
/
address_book.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!D:/Anaconda3/python.exe
# coding:utf-8
import cgi
import cgitb
import codecs
# CGI处理模块
import os
import string
from sqlalchemy import null
# 读取姓名文件,并将其转换为列表
fo = codecs.open("./data/name", "r", encoding="utf-8")
# print("文件名为: ", fo.name)
list_name = []
for line in fo.readlines(): # 依次读取每行
line = line.strip() # 去掉每行头尾空白
list_name.append(line)
# print(list_name)
fo.close()
# 读取性别文件,并将其转换为列表
fo = codecs.open("./data/sex", "r", encoding="utf-8")
# print("文件名为: ", fo.name)
list_sex = []
for line in fo.readlines(): # 依次读取每行
line = line.strip() # 去掉每行头尾空白
list_sex.append(line)
# print(list_sex)
fo.close()
# 读取年龄文件,并将其转换为列表
fo = codecs.open("./data/age", "r", encoding="utf-8")
# print("文件名为: ", fo.name)
list_age = []
for line in fo.readlines(): # 依次读取每行
line = line.strip() # 去掉每行头尾空白
list_age.append(line)
# print(list_age)
fo.close()
# 读取电话文件,并将其转换为列表
fo = codecs.open("./data/tel", "r", encoding="utf-8")
# print("文件名为: ", fo.name)
list_tel = []
for line in fo.readlines(): # 依次读取每行
line = line.strip() # 去掉每行头尾空白
list_tel.append(line)
# print(list_tel)
fo.close()
print("Content-type: text/html\n\n")
print
print("<b>通讯录</b><br>")
print("<ul>")
for i in range(len(list_name)):
print("<li><table><tr><td>姓名: %s ;</td><td>性别: %s ;</td><td>年龄: %s ;</td><td>电话: %s ;</td></tr></table></li>" %
(list_name[i], list_sex[i], list_age[i], list_tel[i]))
print("</ul>")
print('<p><a href="/index.html">back</a></p>')