PYTHON str_getcsv

is this article helpful?
Python replacement for PHP's str_getcsv [ edit | history ]
import csv
import io

def str_getcsv(string, delimiter=',', enclosure='"', escape='\\'):
    with io.StringIO(string) as f:
        reader = csv.reader(f, delimiter=delimiter, quotechar=enclosure, escapechar=escape)
        return next(reader)

PHP str_getcsv

PHP original manual for str_getcsv [ show | ]


(PHP 5 >= 5.3.0)

str_getcsv Parse a CSV string into an array


array str_getcsv ( string $input [, string $delimiter [, string $enclosure [, string $escape ]]] )

Similar to fgetcsv() this functions parses a string as its input unlike fgetcsv() which takes a file as its input.



The string to parse.


Set the field delimiter (one character only). Defaults as a comma.


Set the field enclosure character (one character only). Defaults as a double quotation mark.


Set the escape character (one character only). Defaults as a backslash (\)

Return Values

Returns an indexed array containing the fields read.

See Also

  • fgetcsv() - Gets line from file pointer and parse for CSV fields