mirror of
https://gitlab.com/80486DX2-66/gists
synced 2025-01-26 09:11:54 +05:30
Python: generate_C_lang_token.py: support STDIN as an argument
This commit is contained in:
parent
b965674095
commit
19a84731d8
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
from random import choice
|
from random import choice
|
||||||
from string import ascii_lowercase, ascii_uppercase, digits
|
from string import ascii_lowercase, ascii_uppercase, digits
|
||||||
|
from sys import argv, stdin
|
||||||
|
|
||||||
first_char_alphabet = ascii_uppercase + ascii_lowercase + "_"
|
first_char_alphabet = ascii_uppercase + ascii_lowercase + "_"
|
||||||
alphabet = first_char_alphabet + digits
|
alphabet = first_char_alphabet + digits
|
||||||
@ -14,6 +15,10 @@ alphabet = first_char_alphabet + digits
|
|||||||
random_token = lambda n: \
|
random_token = lambda n: \
|
||||||
"".join( \
|
"".join( \
|
||||||
[choice(first_char_alphabet)] + \
|
[choice(first_char_alphabet)] + \
|
||||||
[choice(alphabet) for i in range(n - 1)]) if n > 0 else ""
|
[choice(alphabet) for i in range(n - 1)]) if (n := int(n)) > 0 else ""
|
||||||
|
|
||||||
|
if "-" in argv[1:] and stdin:
|
||||||
|
print(random_token(list(stdin)[0]))
|
||||||
|
else:
|
||||||
|
print("Random token:", random_token(input("Token length? ")))
|
||||||
|
|
||||||
print("Random token:", random_token(int(input("Token length? "))))
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user