2019-11-01から1ヶ月間の記事一覧

(Python)関数の引数の*とか**とか

def f(a, b, c, d=0, e=0): print(a + b + c + d + e) # => 15 def f_args(*args): print(type(args)) # => <class 'tuple'> print(args) # => (1, 2, 3) def f_kwargs(**kwargs): print(type(kwargs)) # => <class 'dict'> print(kwargs) # => {'a': 1, 'b': 2, 'c': 3} array = [1, 2, 3</class></class>…

(Python)SQL、プリペアードステートメント

プリペアードステートメントを使うには、コネクションからカーソルを取得するときにprepared=Trueを渡す。 import mysql.connector config = { "host": "localhost", "database": "test_db", "user": "masawa", "password": "masawa" } conn = mysql.connect…

(Python,MySQL)DBアクセスサンプル

C:\Users\masawa>pip install mysql-connector-python import mysql.connector config = { "host": "localhost", "database": "test_db", "user": "masawa", "password": "masawa" } conn = mysql.connector.connect(**config) cursor = conn.cursor() curso…

(MySQL)CREATE USERからCRATE TABLEまで一連の作業

C:\Users\masawa>mysql -u root -p mysql> create user 'masawa'@'localhost' identified by 'masawa'; Query OK, 0 rows affected (0.01 sec) mysql> select user, host, plugin from mysql.user; +------------------+-----------+-----------------------…