- Defaults to
autocommit=False
connection = pymysql.connect(user='user', db='test')
cursor = connection.cursor()
cursor.execute('insert into test (value) values (10)')| import logging | |
| logger = logging.getLogger('simple_example') | |
| logger.setLevel(logging.DEBUG) | |
| # create file handler that logs debug and higher level messages | |
| fh = logging.FileHandler('spam.log') | |
| fh.setLevel(logging.DEBUG) | |
| # create console handler with a higher log level | |
| ch = logging.StreamHandler() | |
| ch.setLevel(logging.ERROR) |
| from twisted.enterprise import adbapi | |
| from twisted.python import log | |
| import MySQLdb | |
| class ReconnectingConnectionPool(adbapi.ConnectionPool): | |
| """Reconnecting adbapi connection pool for MySQL. | |
| This class improves on the solution posted at | |
| http://www.gelens.org/2008/09/12/reinitializing-twisted-connectionpool/ | |
| by checking exceptions by error code and only disconnecting the current |
| """ | |
| A demo of creating a new database via SQL Alchemy. | |
| Under MIT License from sprin (https://gist.github.com/sprin/5846464/) | |
| This module takes the form of a nosetest with three steps: | |
| - Set up the new database. | |
| - Create a table in the new database. | |
| - Teardown the new database. | |
| """ |
| #!/usr/bin/env python3 | |
| '''Serving dynamic images with Pandas and matplotlib (using flask).''' | |
| import matplotlib | |
| matplotlib.use('Agg') | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import pandas as pd | |
| from io import BytesIO |
| async def main(): | |
| coroutine1 = do_some_work(1) | |
| coroutine2 = do_some_work(2) | |
| coroutine3 = do_some_work(4) | |
| tasks = [ | |
| asyncio.ensure_future(coroutine1), | |
| asyncio.ensure_future(coroutine2), | |
| asyncio.ensure_future(coroutine3) | |
| ] |
| import pandas as pd | |
| import pymysql | |
| from sqlalchemy import create_engine | |
| engine = create_engine('mysql+pymysql://<user>:<password>@<host>[:<port>]/<dbname>') | |
| df = pd.read_sql_query('SELECT * FROM table', engine) | |
| df.head() |