From f252b5917ea18d0358e605c523dd62b1c6af784f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 22 May 2020 17:55:04 +0200 Subject: [PATCH] CSV, SQLite --- README.md | 14 +++++++------- index.html | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b204ef5..4175d07 100644 --- a/README.md +++ b/README.md @@ -1775,7 +1775,7 @@ import csv ### Read ```python - = csv.reader(, dialect='excel', delimiter=',') + = csv.reader() # Also: `dialect='excel', delimiter=','`. = next() # Returns next row as a list of strings. = list() # Returns list of remaining rows. ``` @@ -1783,7 +1783,7 @@ import csv ### Write ```python - = csv.writer(, dialect='excel', delimiter=',') + = csv.writer() # Also: `dialect='excel', delimiter=','`. .writerow() # Encodes objects using `str()`. .writerows() # Appends multiple rows. ``` @@ -1889,8 +1889,8 @@ db.executemany('', ) # Runs execute() many times. ```python # $ pip3 install mysql-connector from mysql import connector -db = connector.connect(host=, user=, password=, database=) - = db.cursor() +db = connector.connect(host=, …) # `user=, password=, database=`. + = db.cursor() # Only cursor has execute method. .execute('') # Can raise a subclass of connector.Error. .execute('', ) # Replaces '%s's in query with values. .execute('', ) # Replaces '%()s's with values. @@ -1912,7 +1912,7 @@ Bytes ```python = bytes() # Ints must be in range from 0 to 255. = bytes(, 'utf-8') # Or: .encode('utf-8') - = .to_bytes(n_bytes, …) # `byteorder='big/little', signed=False` + = .to_bytes(n_bytes, …) # `byteorder='big/little', signed=False`. = bytes.fromhex('') # Hex numbers can be separated by spaces. ``` @@ -1920,7 +1920,7 @@ Bytes ```python = list() # Returns ints in range from 0 to 255. = str(, 'utf-8') # Or: .decode('utf-8') - = int.from_bytes(, …) # `byteorder='big/little', signed=False` + = int.from_bytes(, …) # `byteorder='big/little', signed=False`. '' = .hex() # Returns a string of hexadecimal numbers. ``` @@ -2016,7 +2016,7 @@ Memory View ```python = list() # Returns list of ints or floats. = str(, 'utf-8') # Treats mview as a bytes object. - = int.from_bytes(, …) # `byteorder='big/little', signed=False` + = int.from_bytes(, …) # `byteorder='big/little', signed=False`. '' = .hex() # Treats mview as a bytes object. ``` diff --git a/index.html b/index.html index 7c89551..8210fa2 100644 --- a/index.html +++ b/index.html @@ -1590,7 +1590,7 @@ CompletedProcess(args=['bc', Read
<reader> = csv.reader(<file>, dialect='excel', delimiter=',')
+

Read

<reader> = csv.reader(<file>)       # Also: `dialect='excel', delimiter=','`.
 <list>   = next(<reader>)           # Returns next row as a list of strings.
 <list>   = list(<reader>)           # Returns list of remaining rows.
 
@@ -1598,7 +1598,7 @@ CompletedProcess(args=['bc', 'newline=""'
argument, or newlines embedded inside quoted fields will not be interpreted correctly! -

Write

<writer> = csv.writer(<file>, dialect='excel', delimiter=',')
+

Write

<writer> = csv.writer(<file>)       # Also: `dialect='excel', delimiter=','`.
 <writer>.writerow(<collection>)     # Encodes objects using `str(<el>)`.
 <writer>.writerows(<coll_of_coll>)  # Appends multiple rows.
 
@@ -1684,8 +1684,8 @@ db.executemany('<query>', <coll_of_abo

MySQL

Has a very similar interface, with differences listed below.

# $ pip3 install mysql-connector
 from mysql import connector
-db = connector.connect(host=<str>, user=<str>, password=<str>, database=<str>)
-<cursor> = db.cursor()
+db = connector.connect(host=<str>, …)           # `user=<str>, password=<str>, database=<str>`.
+<cursor> = db.cursor()                          # Only cursor has execute method.
 <cursor>.execute('<query>')                     # Can raise a subclass of connector.Error.
 <cursor>.execute('<query>', <list/tuple>)       # Replaces '%s's in query with values.
 <cursor>.execute('<query>', <dict/namedtuple>)  # Replaces '%(<key>)s's with values.
@@ -1701,13 +1701,13 @@ db = connector.connect(host=<str>, user=<str>, password=<str>,
 
 

Encode

<bytes> = bytes(<coll_of_ints>)          # Ints must be in range from 0 to 255.
 <bytes> = bytes(<str>, 'utf-8')          # Or: <str>.encode('utf-8')
-<bytes> = <int>.to_bytes(n_bytes, …)     # `byteorder='big/little', signed=False`
+<bytes> = <int>.to_bytes(n_bytes, …)     # `byteorder='big/little', signed=False`.
 <bytes> = bytes.fromhex('<hex>')         # Hex numbers can be separated by spaces.
 

Decode

<list>  = list(<bytes>)                  # Returns ints in range from 0 to 255.
 <str>   = str(<bytes>, 'utf-8')          # Or: <bytes>.decode('utf-8')
-<int>   = int.from_bytes(<bytes>, …)     # `byteorder='big/little', signed=False`
+<int>   = int.from_bytes(<bytes>, …)     # `byteorder='big/little', signed=False`.
 '<hex>' = <bytes>.hex()                  # Returns a string of hexadecimal numbers.
 
@@ -1786,7 +1786,7 @@ db = connector.connect(host=<str>, user=<str>, password=<str>,
<list>  = list(<mview>)                        # Returns list of ints or floats.
 <str>   = str(<mview>, 'utf-8')                # Treats mview as a bytes object.
-<int>   = int.from_bytes(<mview>, …)           # `byteorder='big/little', signed=False`
+<int>   = int.from_bytes(<mview>, …)           # `byteorder='big/little', signed=False`.
 '<hex>' = <mview>.hex()                        # Treats mview as a bytes object.
 

#Deque

A thread-safe list with efficient appends and pops from either side. Pronounced "deck".

from collections import deque