【问题标题】:How to solve IPAddr object has no attribute split error如何解决 IPAddr 对象没有属性拆分错误
【发布时间】:2016-05-18 21:19:47
【问题描述】:

这是我的代码

from pox.lib.addresses import IPAddr
def ip_atoi(st):
"""
function to convert ip address to integer value
"""
  st=st.split(".")
  return int("%02x%02x%02x%02x"%(int(st[0]),int(st[1]),int(st[2]),int(st[3])),16)
  1. 当我在 pox 控制器中运行此脚本时,我收到错误提示

    AttributeError: 'IPAddr' object has no attribute 'split'
    

【问题讨论】:

  • 对我来说似乎很简单。 st 是一个IPAddr 对象,而IPAddr 对象没有split 方法,因此当您尝试在IPAddr 上调用split 时它会崩溃。
  • IPAddr 类中有一个方法toStr()。您应该先调用st.toStr(),然后再拆分它。第 294 行github.com/noxrepo/pox/blob/carp/pox/lib/addresses.py

标签: python python-2.7 sdn pox


【解决方案1】:

原因是st 不是字符串,而是IPAddr 对象。您可能想要做的是:

st = str(st).split(".")

【讨论】:

    猜你喜欢
    • 2022-01-16
    • 1970-01-01
    • 2019-09-08
    • 2020-10-25
    • 2015-07-14
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多