Ben Chuanlong Du's Blog

It is never too late to learn.

Connect to MySQL Using PyMySQL

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

sudo pip3 install PyMySQL

Tricks

  1. Connection in PyMySQL is not autocommit by default. You must commit to save your changes.

    # suppose conn is the connection object
    conn.commit()
    
  2. parameterized sql: %s …

Connect to Databases Using pyodbc in Python

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

pyodbc only supports qmark

https://github.com/mkleehammer/pyodbc/wiki

Unicode Converter Buffer Overflow

This issues arises in Python3 but not Python2, so the simplest way is to use Python2 if …

Tips on Python Flask

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

app.run(host= '0.0.0.0')

  1. jsonify auto does the conversion between None (Python) and null (JS).

Tips on MySQL

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

sudo service mysql restart
mysqladmin -u root -p variables | grep port

mysqladmin --help list the locations of my.cnf.

mysqladmin --help

Python Packages

  1. peewee

  2. PyMySQL

  3. MySQLdb

References

Tips on Dataset in PyTorch

  1. If your data can be fit into the CPU memory, it is a good practice to save your data into one pickle file (or other format that you know how to deserialize). This comes with several advantages. First, it is easier and faster to read from a single big file rather than many small files. Second, it avoids the possible system error of openning too many files (even though avoiding lazying data loading is another way to fix the issue). Some example datasets (e.g., MNIST) have separate training and testing files (i.e., 2 pickle files), so that research work based on it can be easily reproduced. I personally suggest that you keep only 1 file containing all data when implementing your own Dataset class. You can always use the function torch.utils.data.random_split