def test_open_csv(filepath, row=ROW): filename = str(filepath) with open_csv(filename, 'w') as w: w.writerow(row) with open_csv(filename, 'r') as r: assert list(r) == [row] with open_csv(filename) as r: assert list(r) == [row]
def readCsv(fileUrl): content = "" # if os.path.exists(fileUrl): if exists(fileUrl): try: with open_csv(fileUrl) as reader: for row in reader: content += (''.join(row)).replace(' ','') except Exception as e: with open_csv(fileUrl, encoding='gbk') as reader: for row in reader: content += (''.join(row)).replace(' ','') return content
def construct_regions(csv_file): regions = dict() for region_name in available_regions: regions[region_name] = [], [] with csv23.open_csv(csv_file) as reader: # Iterate the current row/day: for row in reversed(list(reader)[1:]): # total_cases = row[0] # acc_cases = row[1] novel_regional_cases = row[2:24] # novel_iva_cases = row[25] # acc_iva_cases = row[26] date = row[27] for i, reg in enumerate(regions): x, y = regions[reg] x.append(str(date + " 00:00:00")) y.append(int(novel_regional_cases[i])) return regions
def test_open_csv_mode_invalid(mode, filename='nonfile'): with pytest.raises(ValueError, match=r'invalid mode'): open_csv(filename, mode)
os.chdir("") _________________ @pip install csv23 @Package import from outside to use (Like to read csv, Audio file) We have different CSV readers like: CVS or CSV23 as we imported below (They are defined by different users. just a difference) @How to Google search: python package for Audio file or go to github and select the python : Link https://github.com/vinta/awesome-python @For example we need to read a PDF then we search on the google then we can import just once in a conputer then use it. >>> import csv23 >>> with csv23.open_csv('C:/Users/HP/Downloads/lsd_math_score_data.csv') as reader: # doctest: +SKIP ... for row in reader: ... print(', '.join(row)) """Spam!, Spam!, Spam!' Spam!, Lovely Spam!, Lovely Spam!'"""