python 数组写入文件格式控制
发布网友
发布时间:2022-04-25 10:53
我来回答
共1个回答
热心网友
时间:2022-04-19 03:17
def writeToTxt(list_name,file_path):
try:
fp = open(file_path,"w+")
for item in list_name:
fp.write(str(item)+"\n")//list中一项占一行
fp.close()
except IOError:
print("fail to open file")
if __name__ == "__main__":
list_name = [ 3.00008000 +0.j,-10.58085662-19.4778165j,5.87334700 +4.733817j, -0.86048738 -0.5688545j,17.35029000 +0.j,-0.86048738 +0.5688545j,5.87334700 -4.733817j,-10.58085662+19.4778165j] //你的list
file_path = r"hello.txt"
writeToTxt(list_name,file_path)