Mar-21-2018, 02:00 PM
Hello,
I'm trying to display a list of databases to a user and have them make a selection based on number. Once the selection is made, I'd like to construct a connection string from their input. So far, I have basic code to have the user connect but I'm unable to take their database input and construct and append it to the connection string.
Thanks!
I'm trying to display a list of databases to a user and have them make a selection based on number. Once the selection is made, I'd like to construct a connection string from their input. So far, I have basic code to have the user connect but I'm unable to take their database input and construct and append it to the connection string.
import cx_Oracle import getpass # Database List db_list = ['TEST11C', 'TEST12C'] x = 0 print ('\nChoose a database: ') for i in db_list: x += 1 print(x, i) while True: try: # Input username and password uname = input('\nEnter username: ') pw = getpass.getpass(prompt='Enter password: ') conn_str = u'%s/%s@<DATABASE>' % (uname, pw) conn = cx_Oracle.connect(conn_str) c = conn.cursor() break except cx_Oracle.DatabaseError as e: error, = e.args print("\nInvalid username/password. Please try again.")Any idea how I can display a list, have the user select a number from the list and take the corresponding database name and add it to the connection string?
Thanks!