import dataset
'''
# connecting to a SQLite database
db = dataset.connect('sqlite:///mydatabase.db')
# connecting to a MySQL database with user and password
db = dataset.connect('mysql://user:password@localhost/mydatabase')
# connecting to a PostgreSQL database
db = dataset.connect('postgresql://scott:tiger@localhost:5432/mydatabase')
'''
db=dataset.connect('mysql://root:root@localhost/data_wrangling')
#創建一個 Python 字典,裏面是我們要保存的數據
my_data_source = {
'url':
'http://www.tsmplug.com/football/premier-league-player-salaries-club-by-club/',
'description': 'Premier League Club Salaries',
'topic': 'football',
'verified': False,
}
#創建名爲 data_sources 的新表
table=db['data_sources']
#將第一個數據源插入新表
table.insert(my_data_source)
#顯示我們保存在 data_sources 表中的所有數據源
sources=db['data_sources'].all()
print(sources)
導入MySQL了可能會報錯:ModuleNotFoundError: No module named 'MySQLdb', 解決辦法:pip install mysqlclient。