近期在做大批量提交的作用,大批量提交使用的是以分号做为分节符的csv文件。在产品测试为了更好地检测大批量提交的作用,*须大批量的信息实现检测。
这个时候我便想起还可以使用Python转化成csv开展检测。
*,在PyCharm中挑选 File -> New -> Python File
特定文件夹名称 例如 generate_CSV_file.py
下面便是敲代码了:
import csv import osdef generate_csv(): current_dir = os.path.abspath('.') file_name = os.path.join(current_dir, "generated_800rows.csv") # open file in binary model to avoid generate empty line in Windows csvfile = open(file_name, 'ab ') writer = csv.writer(csvfile, delimiter=',') header = ['Scheduled KPI Plan name', 'Description', 'Plan Type', 'Visibility', 'Location Filter', 'Resource Filter', 'Time Filter', 'Calculation Model', 'Alert_Rule_Group', 'Multi_Attribute_Filter', 'RECURRENCE_TYPE', 'Execute Every', 'Executed On', 'Start Scheduling Date/Time', 'End Scheduling Date/Time'] writer.writerow(header) rows = [] one_row = [] index_of_rows = 0 while (index_of_rows < 400): index_of_rows = index_of_rows 1 one_row = ['KPITST_MAR5_' str(index_of_rows), 'Test 20190619', 'Scheduled KPI Plan', 'Global', 'BUSER2_GLOBAL', 'ATP_RF_1', 'PF_HAN', 'ATP_KPI_CALMODEL', 'ATP_KPI_ALERTS_GP', '', 'Minutes', 5, '', '2019-07-05T08:00:00.000Z', '2019-12-13T08:00:00.000Z'] rows.append(one_row) while (index_of_rows < 800): index_of_rows = index_of_rows 1 one_row = ['KPITST_MAR5_' str(index_of_rows), 'Test 20190619', 'Scheduled KPI Plan', 'Global', 'BU_CREATED_GLOBAL', 'BUSER2_GLOBAL', 'ATP_PAST1', 'ATP_KPI_CALMODEL', 'ATP_KPI_ALERTS_GP', '', 'Days', 1, '', '2019-07-12T08:00:00.000Z', '2019-10-13T08:00:00.000Z'] rows.append(one_row) writer.writerows(rows); csvfile.close() if ._name._ == '._main._': generate_csv()
进行编码后,鼠标右键-> Run 该py 文档。
运作取得成功后,便会形成一个.csv文件,默认设置储存部位是
开启转化成的csv文件,能够看见该csv文件的**行是header。