【问题标题】:Parsing a set of range of numbers解析一组数字范围
【发布时间】: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.7python2.7 上重现

标签: python python-3.x python-2.7


【解决方案1】:

你的命令必须是'str'类型:

f.write(str(set(x).intersection(y)))

【讨论】:

    猜你喜欢
    • 2018-06-30
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    • 2012-04-20
    • 2014-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多