Here is a quick post on Python.

I am trying here to connect to a device and do stuff … more to come. A key step would be to actually connect to the device first – and for that we would normally need a username, a password, or both.

Whilst reading input from the keyboard is fairly easy to do, I found it was a slightly trickier to get the characters “masked” – as required when typing passwords. Ok … there is a way by using the Python module getpass. This method however would not provide me any feedback on the screen whatsoever – all you see is a blank screen!

I felt I had to reinvent the wheel here … All I want is a routine which reads my password and gives me feedback by means of asterisks on the screen.

To those new to programming, read here should be understood as asking for user input!

The pseudocode

  • Loop Reading characters forever (condition is always true)
  • if the character is CR (Carriage Return/Enter) then break the loop (go to break)
    • otherwise, add the chacacter to the password string
  • break: print the password

Here is how my script looks like, as well as the result:


Notice that in my script I am still using the getch module which is not built-in; I had to install this separately after a lil’ bit of headache. Without going into too much detail, you basically need to manually download the getch module and install it using pip

Should you get compilation errors (like not being able to find .h files), make sure you install python-dev first and try again.

Thank you,
View Rafael A Couto Cabral's profile on LinkedIn

Comments are closed.