csvFileManager.py
# 1.导入代码库
import csv
# 2.指定csv文件所在的路径
path = r"C:\Users\51Testing\PycharmProjects\SeleniumTest2\test_data\register_test_cases.csv"
# print(path)
# 3.打开csv文件
file = open(path)
# 4.读取csv文件中的内容
table = csv.reader(file)
# 5.打印csv文件的内容
for row in table:
print(row)
csvFileManager2.py
import csv
import os
def reader(filename):
list = []
# path = "../test_data/" + filename
base_path = os.path.dirname(__file__) # C:\Users\51Testing\PycharmProjects\SeleniumTest2\func
path = base_path.replace("func","test_data/" + filename)
# C:\Users\51Testing\PycharmProjects\SeleniumTest2\func - func + test_data/ + filename
# C:\Users\51Testing\PycharmProjects\SeleniumTest2\test_data\register_test_cases.csv
# file = open(path)
with open(path) as file:
table = csv.reader(file)
i = 0
for row in table:
if i == 0:
pass
else:
list.append(row)
i = i + 1
return list
if __name__ == '__main__':
base_path = os.path.dirname(__file__) # C:\Users\51Testing\PycharmProjects\SeleniumTest2\func
path = base_path.replace("func","test_data/" + "test_result.csv")
file = open(path, 'w')
list = reader('export_user.csv')
for row in list:
print(row[0])
file.write(row[0]+'\n')