diff --git a/README.md b/README.md index c991e15..5b5119b 100644 --- a/README.md +++ b/README.md @@ -1649,18 +1649,24 @@ b'.\n..\nfile1.txt\nfile2.txt\n' CSV --- ```python -import csv - = csv.reader(, dialect='excel', delimiter=',') - = next() # Returns next row as list of strings. +from csv import reader, writer ``` +### Read ```python - = csv.writer(, dialect='excel', delimiter=',') -.writerow() # Encodes objects using `str()`. -.writerows() + = reader(, dialect='excel', delimiter=',') + = next() # Returns next row as list of strings. ``` * **File must be opened with `'newline=""'` argument, or newlines embedded inside quoted fields will not be interpreted correctly!** +### Write +```python + = writer(, dialect='excel', delimiter=',') +.writerow() # Encodes objects using `str()`. +.writerows() +``` +* **File must be opened with `'newline=""'` argument, or an extra '\r' will be added on platforms that use '\r\n' linendings!** + ### Parameters * **`'dialect'` - Master parameter that sets the default values.** * **`'delimiter'` - A one-character string used to separate fields.** diff --git a/index.html b/index.html index 1f25cb6..5280ece 100644 --- a/index.html +++ b/index.html @@ -1479,18 +1479,24 @@ os.replace(from, to) # Same, but overwr 0 -

#CSV

import csv
-<reader> = csv.reader(<file>, dialect='excel', delimiter=',')
-<list>   = next(<reader>)          # Returns next row as list of strings.
+

#CSV

from csv import reader, writer
+
+ +

Read

<reader> = reader(<file>, dialect='excel', delimiter=',')
+<list>   = next(<reader>)           # Returns next row as list of strings.
 
-
<writer> = csv.writer(<file>, dialect='excel', delimiter=',')
-<writer>.writerow(<collection>)    # Encodes objects using `str(<el>)`.
-<writer>.writerows(<coll_of_coll>)
-
  • File must be opened with 'newline=""' argument, or newlines embedded inside quoted fields will not be interpreted correctly!
+

Write

<writer> = writer(<file>, dialect='excel', delimiter=',')
+<writer>.writerow(<collection>)     # Encodes objects using `str(<el>)`.
+<writer>.writerows(<coll_of_coll>)
+
+ +
    +
  • File must be opened with 'newline=""' argument, or an extra '\r' will be added on platforms that use '\r\n' linendings!
  • +

Parameters

  • 'dialect' - Master parameter that sets the default values.
  • 'delimiter' - A one-character string used to separate fields.
  • @@ -1566,7 +1572,7 @@ db.close()
    • New database will be created if path doesn't exist.
    -

    Read

    cursor = db.execute('<query>')
    +

    Read

    cursor = db.execute('<query>')
     if cursor:
         <tuple> = cursor.fetchone()               # First row. Also next(cursor).
         <list>  = cursor.fetchall()               # Remaining rows.
    @@ -1575,7 +1581,7 @@ db.close()
     
    • Returned values can be of type str, int, float, bytes or None.
    -

    Write

    db.execute('<query>')
    +

    Write

    db.execute('<query>')
     db.commit()