【问题标题】:How to pass Command Line Arguments in Python 3如何在 Python 3 中传递命令行参数
【发布时间】:2020-08-27 17:08:33
【问题描述】:

如何正确传递命令行参数以将数字分配给变量。下面是我创建的一个简单的密码生成器,但在通过终端传递参数时无法使它们起作用:

#!/usr/bin/env python3
# This script creates a secure password using all available key combinations.

# System arguments aka command line arguments

import secrets , string, os, sys
from sys import argv

chars = string.ascii_letters+string.punctuation+string.digits

argv = one, two

print()
#pwd_length = int(input('Enter the length of the desired password: '))
pwd_length = two
print()
print('[+] ' + 'Your secure password is:')
print()

for n in range(1):
    output = ""
    for i in range(pwd_length):
        next_index = secrets.SystemRandom().randrange(len(chars))
        output = output + chars[next_index]
    print(output)
print()

【问题讨论】:

    标签: python-3.x arguments parameter-passing command-line-arguments


    【解决方案1】:

    如果有人想知道如何进行命令行争论,结果很简单,这是解决方案:

    #!/usr/bin/env python3
    # This script creates a secure password using all available key combinations.
    
    import secrets , string, os, sys
    chars = string.ascii_letters+string.punctuation+string.digits
    pwd_length = int(sys.argv[1])
    
    print("\n",'[+] ' + 'Your secure password is:',"\n")
    
    for n in range(1):
        output = ""
        for i in range(pwd_length):
            next_index = secrets.SystemRandom().randrange(len(chars))
            output = output + chars[next_index]
        print(output,"\n")
    

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 2019-07-16
      • 1970-01-01
      • 1970-01-01
      • 2018-03-03
      • 2011-08-22
      • 2016-03-18
      • 1970-01-01
      相关资源
      最近更新 更多