python build in function_python-‘builtin_function_or_method’对象没有属性...

我有一个奇怪的问题,

我创建了以下代码,以1为增量随机生成1和x之间的数字并将其存储

import random

bootstrap_node_list_recieved = [] #List of all nodes addresses recieved during the bootstrap peroid - Is a list so we can compare duplicatition probability etc

average_getAdrr_no_node_response = 100 #Number or nodes typically sent when a node requests a getAddr message

network_ip_node_size = 5000 # Number of IP addresses / nodes that have been seen on the network in the past 2 weeks

#Move into calculations.py when ready

#Number of nodes recieved (Bootstrap)

def bootstrap_node_getAddr():

#### TODO ####

#Random generation of nodes (number represents a single node), from 1 to x for an average amount of nodes

# node_list=[random.randrange(1,network_ip_node_size,1) for _ in range (average_getAdrr_no_node_response)]

for i in range (average_getAdrr_no_node_response):

bootstrap_node_list_recieved.append(random.randrange(1,network_ip_node_size,1))

print 'bootstrap_node_getAddr: ', bootstrap_node_list_recieved

# return bootstrap_node_list_recieved

bootstrap_node_getAddr()

该代码本身可以正常工作,但是当我将其插入到我的主代码库中时,出现错误

Traceback (most recent call last):

File "BootstrapBTC.py", line 117, in query_dns_servers

bootstrap_node_getAddr()

File "/home/richard/Dropbox/PhD/Simulator BTC - Ours/Calculations.py", line 33, in bootstrap_node_getAddr

bootstrap_node_list_recieved.append(random.randrange(1,network_ip_node_size,1))

AttributeError: 'builtin_function_or_method' object has no attribute 'randrange'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File "BootstrapBTC.py", line 90, in run

yield self.env.process(query_dns_servers(env, self))

AttributeError: 'builtin_function_or_method' object has no attribute 'randrange'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File "BootstrapBTC.py", line 178, in

env.run()

File "/usr/local/lib/python2.7/dist-packages/simpy/core.py", line 137, in run

self.step()

File "/usr/local/lib/python2.7/dist-packages/simpy/core.py", line 229, in step

raise exc

AttributeError: 'builtin_function_or_method' object has no attribute 'randrange

第90行的代码是

yield self.env.process(query_dns_servers(env, self))

只是打电话

#Average respsonse time from a DNS server

def DnsServerResponse(env, self):

yield self.env.timeout(dns_average_response)

它将随机值附加到模拟时间中,我认为这与这行代码没有任何关系,因为它根本不使用随机库,事实上,到目前为止插入的代码是唯一使用该库的东西

有人知道这个问题是什么吗?真是气死我了!

谢谢 !

尝试将导入更改为随机导入,现在得到:

Traceback (most recent call last):

File "BootstrapBTC.py", line 102, in query_dns_servers

DnsUp = DnsUpProbability()

File "/home/richard/Dropbox/PhD/Simulator BTC - Ours/Calculations.py", line 39, in DnsUpProbability

up = (0 if random() > Prob_DNS_UP else 1)

TypeError: 'module' object is not callable

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值