说明蓝色=命令名称

浅绿=命令参数

浅蓝=选项

紫色=目录

系统环境:CentOS 5.5 x86_64

python版本:Python 2.7.3


随机输出汉字小程序


#!/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)