說明:藍色=命令名稱python
淺綠=命令參數小程序
淺藍=選項dom
紫色=目錄
ide
系統環境:CentOS 5.5 x86_64spa
python版本:Python 2.7.3code
隨機輸出漢字小程序utf-8
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#Author:left_left
import random
import struct
import sys
def get_zi(num):
s = ""
while num:
a = random.randint(0xbf, 0xd7)
b = random.randint(0xa1, 0xfe)
c = struct.pack("BB",a,b)
try:
s += c.decode("gb2312")
num -= 1
except UnicodeDecodeError:
pass
return s
if __name__ == "__main__":
print get_zi(3)get