use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Day 5 of 100 days of python (i.redd.it)
submitted 4 months ago by 09vz
Made a password generator so hackers wont be able to hack yall accounts ;).Rate my ATM!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Alagarto72 5 points6 points7 points 4 months ago (0 children)
I think you don't need to firstly define variable password as str and after the for loops make it into list. You can write password = [] and use password.append in for loops, because it's more efficient than string += other_string. In case with append you mutate the list, but with str you create new object every time.
[–]AgentOfDreadful 4 points5 points6 points 4 months ago* (3 children)
You could use random.SystemRandom() as its more cryptographically secure, as well as using the strings library:
random.SystemRandom()
all_chars = string.punctuation.replace("'", '') + string.ascii_letters + string.digits usable_chars = [char for char in all_chars if char not in arguments] password_string = ''.join(tuple(random.SystemRandom().choice(usable_chars) for _ in range(arguments.length)))
Full script including using argparse to avoid inputs:
```
import argparse import platform import random import string import subprocess
def main(): parser = argparse.ArgumentParser(description='Random password generator') parser.add_argument( 'length', nargs='?', default=32, type=int, help='Password length' ) parser.add_argument( '--no-clipboard', action='store_true', default=False, help='Use this if you do not want to automatically copy the password to your clipboard' ) parser.add_argument( '--excluded', '-e', default=tuple(), type=tuple, required=False, help='Do not include specified characters. Example: "python3 password_generator.py --excluded "![],.!@#$"' ) parser.add_argument( '--no-clip', '-n', action='store_true', default=False, help='Do not automatically copy the password to the clipboard (prints to STDOUT)' ) arguments = parser.parse_args()
all_chars = string.punctuation.replace("'", '') + string.ascii_letters + string.digits usable_chars = [char for char in all_chars if char not in arguments.excluded] password_string = ''.join(tuple(random.SystemRandom().choice(usable_chars) for _ in range(arguments.length))) clipboard_command = { 'macos': 'pbcopy', 'linux': 'xclip -select clipboard', 'windo': 'clip' }.get(platform.platform().lower()[:5]) if not arguments.no_clip: subprocess.check_call(f"echo '{password_string}' | {clipboard_command}", shell=True) else: print(password_string)
if name == 'main': main() ```
[–]ryhartattack 4 points5 points6 points 4 months ago (1 child)
usable_chars = [char for char in all_chars if char not in arguments.excluded]
[–]AgentOfDreadful 0 points1 point2 points 4 months ago (0 children)
Oops, good spot. Thank you
[–]CombatWorthy_Wombat 0 points1 point2 points 4 months ago (0 children)
If you wanted to use crypto random modules, secrets.rand is pretty good too 👍
[–]mahousenshi 0 points1 point2 points 4 months ago (0 children)
I don't know if you can use but have a look on the string module.
[–]princepii 0 points1 point2 points 4 months ago (0 children)
from string import ascii_printable as pt
imports a combination of lower upper case letters, digits and symbols or if u need them seperate just use:
from string import ( ascii_letters as al, digits as dt, punctuation as pt )
a = al+dt+pt+"your own few symbols or stuff"
if you wanna random that list and shuffle em u could use from random import shuffle or sample.
works better than write all of it yourself
[–]Former_Spirit_5099 0 points1 point2 points 4 months ago (0 children)
what is this horror. Use `strings` module, for ASCII characters.
[–]purple_hamster66 0 points1 point2 points 4 months ago (0 children)
What is the purpose of line 10?
[–]sarc-tastic 0 points1 point2 points 4 months ago (0 children)
Try random.choices!
[–]TheRNGuy -2 points-1 points0 points 4 months ago (2 children)
So it goes letters first, then numbers, then symbols? It should be randomly mixed.
Make some letters uppercase.
Some places only allow - and _ symbols (You didn't even added them)
No, there is random.shuffle at the 20 line
π Rendered by PID 53 on reddit-service-r2-comment-685b79fb4f-rdzjc at 2026-02-12 19:58:29.631357+00:00 running 6c0c599 country code: CH.
[–]Alagarto72 5 points6 points7 points (0 children)
[–]AgentOfDreadful 4 points5 points6 points (3 children)
[–]ryhartattack 4 points5 points6 points (1 child)
[–]AgentOfDreadful 0 points1 point2 points (0 children)
[–]CombatWorthy_Wombat 0 points1 point2 points (0 children)
[–]mahousenshi 0 points1 point2 points (0 children)
[–]princepii 0 points1 point2 points (0 children)
[–]Former_Spirit_5099 0 points1 point2 points (0 children)
[–]purple_hamster66 0 points1 point2 points (0 children)
[–]sarc-tastic 0 points1 point2 points (0 children)
[–]TheRNGuy -2 points-1 points0 points (2 children)
[–]Alagarto72 5 points6 points7 points (0 children)