Below is the Python program which will show you how to connect to MariaDB. Here is the code: # Module Imports import mariadb import sys # Connect to MariaDB Platform try: conn = mariadb.connect( user="user", password="password", host="host", port=port, database="database" ) except mariadb.Error as e: print(f"Error connecting to MariaDB Platform: {e}") sys.exit(1) # Get Cursor cur = conn.cursor() try: cur.execute("show databases;") cur.execute("use test_db;") cur.execute("show tables;") for table in cur: print(table) except mariadb.Error as e: print(f"Error: {e}") # Close Connection conn.close()
Below is the Python program which will get file attributes or file related information. Here is the code: import os import sys sys.path.extend(r'mention your file path here') print('Get current working directory : ', os.getcwd()) print('File name : ', os.path.basename(__file__)) print('Directory Name: ', os.path.dirname(__file__)) print('Absolute path of file: ', os.path.abspath(__file__)) print('Absolute directory name: ', os.path.dirname(os.path.abspath(__file__))) # Specify the directory you want to list directory_path = os.getcwd() # List all files and folders in the directory file_list = os.listdir(directory_path) # Get full paths full_paths = [os.path.join(directory_path, file) for file in file_list] print(full_paths)