Search code examples
pythonrpassword-protection

Is there an equivalent to RStudio's ".rs.askForPassword" in Python?


I want to connect to my database in Python, but i don't want to show my password to other users, like .rs.askForPassword does exactly what i need in RStudio. Here's an example:

library(RODBC)
conn = odbcConnect(dsn = "my_dsn", 
                   uid = "name.last_name",
                   pwd = .rs.askForPassword("my.password"))

Is there any way to do this in Python?


Solution

  • You may use getpass()

    import getpass
    
    p = getpass.getpass(prompt='What is your favorite person? ')
    if p.lower() == 'gf':
        print 'Right.  Off you go.'
    else:
        print 'Wrong!'