mardi 11 janvier 2022

How to run the function with multiple argparse

Hello I write my code and want to run this with multiple argparse, but when i try to do it with comma or \ it doesn't work. I'm working on wsl so I use terminal to run function like this.Another problem is when I try to run --possile-sepatators "!@#$$%%" I got the problem bash: !@#: event not found . Code:

import sys
import argparse
import csv
from random import choice
from random import randint
def read_from_csv(path):
    words = []
    with open(path, "r") as file_handle:
        reader = csv.reader(file_handle)
        for row in reader:
            for element in row:
                words.append(element)
    return words

def creating_a_password(list_of_words,args):
    new_string = ""
    if not args.words_number:
        j = 3
        max = j
    else:
        j = args.words_number
        max  = j
    if args.padding_digits:
        dopełnienie = args.padding_digits
    else:
        dopełnienie = 3
    if args.generated_passwords:
        generated_passwords = args.generated_passwords
    else:
        generated_passwords = 1
    a = randint(0, 1000)
    stringa = str(a)
    x = 0
    while x != len(stringa):
        b = randint(0, 1000)
        x = str(b)
        x = len(x)
    j = 0
    list_of_seps = []
    for l in range(generated_passwords):
        for elem in list_of_words:
            if args.possible_separators:
                for sth in args.possible_separators:
                    list_of_seps.append(sth)
                choosing1sep = choice(list_of_seps)
            else:
                choosing1sep = "^"
            if len(new_string) == 0:
                new_string += choosing1sep * dopełnienie
                new_string += str(a)
            if args.minimal_word_length and args.maximal_word_length:
                if (len(elem)>=  args.minimal_word_length) and (len(elem)<= args.maximal_word_length):
                    new_string += elem
                    new_string += choosing1sep
                    j += 1
            else:
                new_string+= elem
                new_string += choosing1sep
                j+= 1
            if j == max :
                new_string += str(b)
                new_string += choosing1sep * dopełnienie
            if j == max:
                break
        print(new_string)




def main(argument):
    parser = argparse.ArgumentParser()
    parser.add_argument("--possible_separators")
    parser.add_argument("--padding-digits")
    parser.add_argument("--padding-symbols-number")
    parser.add_argument("--possible-padding-symbols")
    parser.add_argument("--words_number")
    parser.add_argument("--minimal-word-length")
    parser.add_argument("--maximal-word-length")
    parser.add_argument("--generated-passwords")
    a = read_from_csv("data.txt")
    args = parser.parse_args(argument[1:])
    # number = args.words_number
    b = creating_a_password(a,args)


if __name__ == "__main__":
    main(sys.argv)

I tried for example python3 fileit.py --words_number 3 \ --padding-digits "@#$%". I want to write my program with every argparse argument at the same time. The code is not important, I just want to know how to do it at the same time. Commas doesn't work, spaces doesn't work.




Aucun commentaire:

Enregistrer un commentaire