【发布时间】:2019-05-20 07:21:20
【问题描述】:
我编写了一个简单的代码来查找两组范围之间的交集并打印交集。现在我正在尝试将结果写入文件。但我得到一个错误,说 write() 参数必须是 str 未设置。
import numpy
# initialize A and B
filename = "set.txt"
f = open("set.txt", "w")
x = numpy.arange(4000, 5000, 1)
y = numpy.arange(3500, 5500, 1)
#x.intersection(y)
#print (set(x).intersection(y))
f.write(set(x).intersection(y))
f.close()
它适用于打印,但我包含了它给出的错误
【问题讨论】:
-
无法在
python3.7或python2.7上重现
标签: python python-3.x python-2.7