Python生成随机密码

yipeiwu_com6年前Python基础

本人  python新手,使用的环境是python2.7,勿喷

复制代码 代码如下:

# -*- coding:utf8 -*-
import random
import string
import sys
reload(sys)
sys.setdefaultencoding("utf8")
def random_number():
    pwnumber=input("请输入需要密码个数:")
    pwlength=input("请输入需要密码长度:")
    if  pwlength<=10:
        for i in range(pwnumber):
            number=string.join(random.sample(string.digits+string.letters,pwlength)).replace(' ','')
            print number
    else :
        print "目前只支持10位以下密码,请重试!!"
        random_number()
if __name__=="__main__":
    random_number()

以上就是本文的全部内容了,希望对大家学习python能够有所帮助。

相关文章

python异常触发及自定义异常类解析

python程序运行中,可由程序抛出异常。 异常触发:使用raise命令抛出异常,即可使用异常基类Exception,也可使用自定义异常类(继承Exception类)。 class...

使用Python开发windows GUI程序入门实例

今天终于可以用wxPython开发GUI程序了,非常高兴。把其中的一些注意点写下来以供参考。在windows XP平台下,首先需要做以下环境的配置: 1. 首先是安装python ,安装...

python 调用有道api接口的方法

python 调用有道api接口的方法

初学python ,研究了几天,写了一个python 调用 有道api接口程序 效果看下图: 申明:代码仅供和我一样的初学者学习交流 有道api申请地址http://fanyi.you...

python导出hive数据表的schema实例代码

本文研究的主要问题是python语言导出hive数据表的schema,分享了实现代码,具体如下。 为了避免运营提出无穷无尽的查询需求,我们决定将有查询价值的数据从mysql导入hive中...

利用 Monkey 命令操作屏幕快速滑动

利用 Monkey 命令操作屏幕快速滑动

一、Monkey测试简介 Monkey测试是Android平台自动化测试的一种手段,通过Monkey程序模拟用户触摸屏幕、滑动Trackball、按键等操作来对设备上的程序进行压力测试,...