【发布时间】:2018-06-14 14:28:25
【问题描述】:
我有一个函数如下(我在python2.7上工作):
def ip_split(ip):
rtr, mask = cidr.split('/')
ip = ipaddress.ip_address(unicode(rtr))
if ip.version == 4:
n = ipaddress.IPv4Network(unicode(cidr), strict=False)
else:
n = ipaddress.IPv6Network(unicode(cidr), strict=False)
first, last = n[2], n[-2]
return n, first, last, n[1], n.network_address, mask
n_sub = "%s/%s" % ip_split('10.10.128.1/18')[3:]
Traceback (most recent call last):
File "python", line 18, in <module>
TypeError: not all arguments converted during string formatting
我收到 typeError: not all arguments 在字符串格式化期间转换。
这里有什么问题??
【问题讨论】:
-
好吧
ip_split返回一个 6 元组。这意味着ip_split(..)[3:]返回一个三元组,而格式字符串中只有两个%ss。 -
[3:]返回n[1], n.network_address, mask,但您在"%s/%s" % ip_split('10.10.128.1/18')中只提供了两个字符串格式化目标
标签: python string python-2.7 typeerror output-formatting