Package: aliceCSV
aliceCSV -- A concise and easy-to-use csv modulealiceCSV -- 一个简洁易用的csv模块==这是英文介绍，中文介绍请看中文文档==This module can operate CSV fileas two-dimensional tableand be able toconvert theminto other forms easily.aliceCSV hasstrong compatibilitywith CSVs that does not comply with RFC 4180 or be in incorrect formats.For example, if there is a file named "sheet.csv" and the following is its content.avc,"She said,"I like orange juice.""That is wrong.According to RFC 4180 Definition 7, it's incorrect because the double-quote inside the second field must be escaped by preceding it with another double quote.So the correct version is as following.avc,"She said,""I like orange juice."""If you try to open the wrong one in Excel, it will be interpreted into that one.avcShe said,I like orange juice.""However, aliceCSV can correctly identify the author's true intention for both of them.fromaliceCSVimport*myFile=open("sheet.csv",encoding="utf-8")print(csvTo2dTable(myFile))It will output  the following result.[['avc', 'She said,"I like orange juice."']]And don't worry about this kind of compatibility affecting normal reading. For example, even if you want to express the wrong sheet Excel reads out, it shouldn't be done in that erroneous manner. Such writing is merely guesswork for the interpreter to decipher. The interpretation may vary due to text and interpretation program differences, making it uncertain what it's interpreted as. aliceCSV simply outputs results based on commonly made errors, opting for those that likely reflect the author's true intent.InstallYou can use pip to install it.pip install aliceCSVor clone thisgit clone https://github.com/yourusername/your-repo.git
cd your-repo
python setup.py installHow to use1.Create a two-dimonsion table basing on a csv filecsvTo2dTable(file, [optional]delimiter)file：an _io.BufferedReader of the targeted csv file, which is created by open() a csv filedelimiter : The delimiter used in the CSV file. This parameter can be omitted, with the default value being “,”.For example, there is a file named "sheet.csv".Name,Age,City
Alice,25,New York
Bob,30,San Francisco
Charlie,22,Los AngelesTo open this CSV file as a two-dimensional list using thecsvTo2dTable()function, you can follow this format:fromaliceCSVimportcsvTo2dTablefile_path="sheet.csv"# Using default delimiter (`,`), you can omit the delimiter parametertable=csvTo2dTable(open(file_path))print(table)Replace"sheet.csv"with the actual path to your CSV file. This code snippet demonstrates how to usecsvTo2dTable()to open a CSV file and display its content as a two-dimensional list.WARNING:1.If you are having trouble with CSV files like this, it may be because they have a space after the delimiter "," . So the actual delimiter is ",  ".name, gender, height, address
John, male, 175cm, "123 Main Street, New York, USA"
Emily, female, 160cm, "45 Oxford Road, London, UK"
Michael, male, 180cm, "10 Rue de la Paix, Paris, France"
Sophia, female, 165cm, "25 Alexanderplatz, Berlin, Germany"If you fix it or learn more about it , you can go to the forth part4.Convert CSV files into other formats.2.Converte two-dimensional table into CSV file：TableToCsv(sheet, [optional]output_path, [optional]sheet_encoding, [optional]delimiter, [optional]line_break)sheet: a two-dimensional tableoutput_path: The location for the output result. It can be omitted, with the default value being “output.csv”.sheet_encoding:  The encoding format used in the output file. It can be omitted, with the default value being “utf-8”.delimiter: The delimiter used in the CSV file. It can be omitted,  with the default value being “,”.line_break: The line break used in the output file. It can be omitted, with the default value being "\n".To save a two-dimensional list as a CSV file using thetableToCSV()function, you can use the following example:fromaliceCSVimporttableToCsv# Example two-dimensional listtable=[['Name','Age','City'],['Alice',25,'New York'],['Bob',30,'San Francisco'],['Charlie',22,'Los Angeles']]tableToCSV(table)Then it will output the "output.csv"3.Fix the length of a CSV file or a tableThe  functionfixLineLength()can be used to fix the length of lines in CSV files according to the RFC 4180 standard.It checks the number of fields in each row. If the number of fields in a row is less than the maximum number of fields, an empty field will be added at the end of the row to ensure that the number of fields in each row is the same.fromaliceCSVimportfixLineLength,csvTo2dTable,tableToCSV# Example CSV file: sheet.csvfile_path="sheet.csv"# Open the CSV file as a two-dimensional listfile=open(file_path)table=csvTo2dTable(file)# Fix the line lengths of the CSV filefixed_table=fixLineLength(table)# Output the resultoutput_file=tableToCSV(fixed_table)Replace 'sheet.csv' with the actual CSV file path.4.Convert into CSV files in other formatsMany CSV files use other delimiters, not commas.The following CSV file named "space.csv", which has a space between every two fields, which means it's delimiter is ", " , a comma with a space following.name, gender, height, address
John, male, 175cm, "123 Main Street, New York, USA"
Emily, female, 160cm, "45 Oxford Road, London, UK"
Michael, male, 180cm, "10 Rue de la Paix, Paris, France"
Sophia, female, 165cm, "25 Alexanderplatz, Berlin, Germany"aliceCSV can convert them easily.fixCSV(path, [optional]output_path, [optional]origin_delimiter,                  [optional]target_delimiter, [optional]origin_encoding,                    [optional]target_encoding, [optional]target_line_break)path: The path of the origin CSV file that needs to be convertedoutput_path: The location for the output result. It can be omitted, with the default value being “output.csv”.origin_delimiter: The delimiter of the origin CSV file.It can be omitted, with the default value being “,”.target_delimiter: The delimiter used in the output file.It can be omitted, with the default value being “,”.origin_encoding: The encoding of the the origin file.It can be omitted, with the default value being “utf-8”.target_encoding: The encoding used in the output file.It can be omitted, with the default value being “utf-8”.target_line_break: The line break of the output file.It can be omitted, with the default value being “\n”.You can use the functionfixCSV()to convert CSV files with different formats, as shown in the example below.fromaliceCSVimportfixCSVfixCSV("space.csv",origin_delimiter=", ",target_delimiter=",")This example demonstrates the conversion of the “space.csv” file into the resulting “output.csv” as follows.5.OthersLicensealiceCSV's code in this repo uses the MIT license, see ourLICENSEfile.