資料庫裡有哪些資料表?
在這個練習中,你會再次建立一個引擎連到 'Chinook.sqlite'。
不過,在你從資料庫取出任何資料之前,你需要先知道裡面有哪些資料表!
為此,你會在引擎上使用 .table_names() 方法,將資料表名稱存成一個清單,然後印出該清單。
本練習屬於課程
Python 資料匯入入門
練習說明
- 從模組
sqlalchemy匯入函式create_engine。 - 建立一個連線到 SQLite 資料庫
'Chinook.sqlite'的引擎,並指定給engine。 - 在引擎
engine上使用.table_names()方法,將'Chinook.sqlite'的資料表名稱指定給變數table_names。 - 在終端機列印物件
table_names。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import necessary module
# Create engine: engine
# Save the table names to a list: table_names
# Print the table names to the shell
print(____)