Quick Python question - how to change input to *

In summary, you could probably use the getpass module to echo asterisks instead of input. Alternatively, if you are using stdin, you might be able to use sys.stdin or the msvcrt module to print asterisks instead of input.
  • #1
zeion
466
1

Homework Statement



Hello,

Just a quick question here for Python.
I'm using raw_input to get the user to type in a string, but I want the letters to display as * (like when you enter a password) as they type it. (But not actually register as *). Is this doable in Python?

Thanks.

Homework Equations





The Attempt at a Solution

 
Technology news on Phys.org
  • #2
You could probably copy and modify the getpass module, which doesn't echo any input to the screen, to echo asterisks instead.

That might only work for terminals, though.
 
  • #3
Yeah.. can't seen to work on a PC.
Getting this:

Warning (from warnings module):
File "C:\Python27\lib\getpass.py", line 92
return fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal.
Warning: Password input may be echoed.
 
  • #4
Is there a way to do it with the curses module?
 
  • #5
Are you using IDLE? You might have to use cmd for that to work.

Otherwise, if you are using stdin, you might be able to use sys.stdin or the msvcrt module to print asterisks instead of input.

What are you trying to do?

You could probably work something out using curses.
 
  • #6
Actually I'm just trying to write a game where the other player cannot see what was typed. Is there a way to just delete a line that was displayed?
 
  • #7
Are you doing it in terminal or GUI?
 
  • #8
Tkinter, IIRC, has an option for a text entry box where you can mask input with asterisks.
 
  • #9
jhae2.718 said:
Tkinter, IIRC, has an option for a text entry box where you can mask input with asterisks.

I'm doing it in GUI..

Sorry I don't know what those are. Are they Python modules?
 
  • #10
Tkinter is the default GUI toolkit for Python. Sys and msvcrt are Python modules, but if you are doing GUI, the toolkit should have a provision for password entry which should suit your needs.

What toolkit are you using?
 

1. How do I change the input to a star in Python?

To change the input to a star in Python, you can use the '*' symbol. This symbol represents multiplication in Python and can be used to multiply a number by itself to create a star pattern.

2. Can I change the input to a star in Python without using the multiplication symbol?

Yes, you can use string concatenation to create a star pattern in Python. This involves using a loop to concatenate the '*' symbol to an empty string and then printing the resulting string.

3. How can I change the input to a different character or symbol in Python?

To change the input to a different character or symbol in Python, you can use the replace() method. This method allows you to replace a specific character or string with another character or string.

4. Is there a way to change the input to a star in Python using user input?

Yes, you can use input() to prompt the user for a number and then use that number to create a star pattern in Python. You can also use input() to prompt the user for a specific character or symbol to use for the pattern.

5. Can I change the input to a star in Python without using loops?

Yes, you can use string multiplication to create a star pattern in Python without using loops. This involves multiplying the '*' symbol by the desired number of times to create the pattern.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
5
Views
991
  • Programming and Computer Science
2
Replies
55
Views
4K
  • Programming and Computer Science
Replies
3
Views
315
  • Programming and Computer Science
Replies
7
Views
2K
Replies
11
Views
2K
Replies
17
Views
7K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
18
Views
2K
Back
Top