Python寫一個批量產生帳號的函數

來源:互聯網
上載者:User

標籤:不能   while   使用者   its   拼接字串   not   uppercase   判斷   lines   

批量產生賬戶資訊,產生的賬戶由@sina.com結尾,長度由使用者輸入,產生多少條也由使用者輸入,使用者名稱不能重複,使用者名稱必須由大寫字母、小寫字母和數字組成。

 1 def Users(num,len): # num產生多少條資訊,len帳號的長度 2     ‘‘‘ 3     用交集來判斷是否包含大小寫字母 4     :param num: 產生幾條資料 5     :param len: 帳號的長度 6     :return: 7     ‘‘‘ 8     results = [] # 存放結果的數組 9     uppers = set(string.ascii_uppercase) # 大寫字母10     lowers = set(string.ascii_lowercase) # 小寫字母11     digit = set(string.digits) # 數字12     all_str = string.ascii_letters + string.digits13     count = 014     while count < num:15         res = random.sample(all_str,len) # sample 返回的是一個list16         # 如果set列表中包含大小寫字母和數字17         if set(res) & uppers and set(res) & lowers and set(res) & digit:18             res = ‘‘ .join(res) + ‘@sina.com‘ + ‘\n‘ # 拼接字串19             if res not in results: # 如果res不在列表results中20                 results.append(‘‘ .join(res)) # 將拼接的字串加到results列表中21                 count += 122     with open(‘results.txt‘,‘w‘) as fw:23         fw.writelines(results) # 將列表寫入到檔案中24 25 Users(5,6) # 調用函數

results.txt   產生的資料

1 [email protected]2 [email protected]3 [email protected]4 [email protected]5 [email protected]

 

Python寫一個批量產生帳號的函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.