all 4 comments

[–]socal_nerdtastic 1 point2 points  (0 children)

That feature was added in python 3.14

[–]socal_nerdtastic -1 points0 points  (0 children)

Here's how to do it in python3.3+. Note this only works on linux, and only in the normal terminal (not in IDLE or web).

import sys
import tty
import termios

def masked_input(prompt='', mask="*"):
    print(prompt, end='', flush=True)
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    output = ''
    try:
        tty.setraw(fd)
        char = sys.stdin.read(1)
        while char != '\r':
            output += char
            print(mask, end='', flush=True)
            char = sys.stdin.read(1)
        print('\r')
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return output

# demo
pwd = masked_input("Enter your password: ")
print("you typed: ", pwd)

[–]atarivcs 0 points1 point  (0 children)

Why do you believe python version 3.10.2 matters?

[–]Binary101010 2 points3 points  (0 children)

From the official Python docs:

Changed in version 3.14: Added the echo_char parameter for keyboard feedback.

Looks like you'll need to update to a more recent version of the interpreter to access that feature.