需要帮助创建一个密码生成器。

问题描述 投票:0回答:1

我需要写一个Python程序,它可以

  • 读取文件:wordlist.txt。
  • 预览文件
  • 从文件中随机选择四个单词
  • 显示这四个字来创建一个密码。

我只是不知道从哪里开始,但我从。

import wordlist.txt

python generator
1个回答
0
投票

导入是用来 import Python库。你不能通过 import试试这个

import random  # Import random library

with open("wordlist.txt", mode="r") as f:  # Open file
    file_content = [x.strip() for x in f.readlines()]  # Remove whitespace like \n \t or space
    print(file_content)  # Print wordlist.txt
    print(random.sample(file_content, 4))  # Print 4 random words
© www.soinside.com 2019 - 2024. All rights reserved.