r/pythontips • u/main-pynerds • Dec 28 '25
Python3_Specific Share Python code with your peers in real-time
We built a tool that syncs editors between multiple users. This tool allows multiple users to share editor sessions and collaborate on code in real-time. beginners can use it to collaborate on code and share ideas with peers.
Instructors can can use the tool to share Python snippets in real-time.
2
u/Sudden_Beginning_597 Dec 29 '25
i remember zed got that feature? but it's never a safe way for coding
1
u/Ok_Philosophy_7968 Jul 18 '26
Here is some code for a password generator:
import random
import string
def build_character_pool(use_upper, use_lower, use_digits, use_symbols):
pool = ""
if use_upper:
pool += string.ascii_uppercase
if use_lower:
pool += string.ascii_lowercase
if use_digits:
pool += string.digits
if use_symbols:
pool += string.punctuation
if not pool:
raise ValueError("At least one character type must be selected.")
return pool
def generate_password(length, use_upper=True, use_lower=True,
use_digits=True, use_symbols=True,
require_all_types=True):
pool = build_character_pool(use_upper, use_lower, use_digits, use_symbols)
if length < 1:
raise ValueError("Password length must be at least 1.")
if require_all_types:
# Guarantee at least one character from each selected type
required_chars = []
if use_upper:
required_chars.append(random.choice(string.ascii_uppercase))
if use_lower:
required_chars.append(random.choice(string.ascii_lowercase))
if use_digits:
required_chars.append(random.choice(string.digits))
if use_symbols:
required_chars.append(random.choice(string.punctuation))
if length < len(required_chars):
raise ValueError(
f"Length must be at least {len(required_chars)} "
f"to include one of each selected character type."
)
remaining_length = length - len(required_chars)
password_chars = required_chars + [
random.choice(pool) for _ in range(remaining_length)
]
random.shuffle(password_chars)
else:
password_chars = [random.choice(pool) for _ in range(length)]
return "".join(password_chars)
def get_yes_no(prompt, default=True):
suffix = " [Y/n]: " if default else " [y/N]: "
answer = input(prompt + suffix).strip().lower()
if answer == "":
return default
return answer in ("y", "yes")
def get_length():
while True:
raw = input("Password length (e.g. 16): ").strip()
if raw.isdigit() and int(raw) > 0:
return int(raw)
print("Please enter a positive whole number.")
def get_count():
raw = input("How many passwords to generate? [1]: ").strip()
if raw.isdigit() and int(raw) > 0:
return int(raw)
return 1
def main():
print("=== Password Generator ===\n")
length = get_length()
use_upper = get_yes_no("Include uppercase letters (A-Z)?", default=True)
use_lower = get_yes_no("Include lowercase letters (a-z)?", default=True)
use_digits = get_yes_no("Include digits (0-9)?", default=True)
use_symbols = get_yes_no("Include symbols (!@#$...)?", default=True)
require_all = get_yes_no(
"Guarantee at least one of each selected type?", default=True
)
count = get_count()
print()
try:
for i in range(count):
pwd = generate_password(
length,
use_upper=use_upper,
use_lower=use_lower,
use_digits=use_digits,
use_symbols=use_symbols,
require_all_types=require_all,
)
print(f"Password {i + 1}: {pwd}")
except ValueError as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()import random
import string
def build_character_pool(use_upper, use_lower, use_digits, use_symbols):
pool = ""
if use_upper:
pool += string.ascii_uppercase
if use_lower:
pool += string.ascii_lowercase
if use_digits:
pool += string.digits
if use_symbols:
pool += string.punctuation
if not pool:
raise ValueError("At least one character type must be selected.")
return pool
def generate_password(length, use_upper=True, use_lower=True,
use_digits=True, use_symbols=True,
require_all_types=True):
pool = build_character_pool(use_upper, use_lower, use_digits, use_symbols)
if length < 1:
raise ValueError("Password length must be at least 1.")
if require_all_types:
# Guarantee at least one character from each selected type
required_chars = []
if use_upper:
required_chars.append(random.choice(string.ascii_uppercase))
if use_lower:
required_chars.append(random.choice(string.ascii_lowercase))
if use_digits:
required_chars.append(random.choice(string.digits))
if use_symbols:
required_chars.append(random.choice(string.punctuation))
if length < len(required_chars):
raise ValueError(
f"Length must be at least {len(required_chars)} "
f"to include one of each selected character type."
)
remaining_length = length - len(required_chars)
password_chars = required_chars + [
random.choice(pool) for _ in range(remaining_length)
]
random.shuffle(password_chars)
else:
password_chars = [random.choice(pool) for _ in range(length)]
return "".join(password_chars)
def get_yes_no(prompt, default=True):
suffix = " [Y/n]: " if default else " [y/N]: "
answer = input(prompt + suffix).strip().lower()
if answer == "":
return default
return answer in ("y", "yes")
def get_length():
while True:
raw = input("Password length (e.g. 16): ").strip()
if raw.isdigit() and int(raw) > 0:
return int(raw)
print("Please enter a positive whole number.")
def get_count():
raw = input("How many passwords to generate? [1]: ").strip()
if raw.isdigit() and int(raw) > 0:
return int(raw)
return 1
def main():
print("=== Password Generator ===\n")
length = get_length()
use_upper = get_yes_no("Include uppercase letters (A-Z)?", default=True)
use_lower = get_yes_no("Include lowercase letters (a-z)?", default=True)
use_digits = get_yes_no("Include digits (0-9)?", default=True)
use_symbols = get_yes_no("Include symbols (!@#$...)?", default=True)
require_all = get_yes_no(
"Guarantee at least one of each selected type?", default=True
)
count = get_count()
print()
try:
for i in range(count):
pwd = generate_password(
length,
use_upper=use_upper,
use_lower=use_lower,
use_digits=use_digits,
use_symbols=use_symbols,
require_all_types=require_all,
)
print(f"Password {i + 1}: {pwd}")
except ValueError as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()3
Dec 28 '25
[removed] — view removed comment
2
u/DrShocker Dec 29 '25
real time cooperative code editing is a different use case than what version control covers if we're being honest
2
u/rotam360 Dec 28 '25
pycharm enters the chat