如果我从库中导入一个类,而这个类使用的变量/常量是在库中定义的,但是在类之外,我可以更改这个值吗?你知道吗
我正在写剧本:
from bitcoin.rpc import RawProxy
p = RawProxy()
hash = '0000000000000001b6b9a13b095e96db41c4a928b97ef2d944a9b31b2cc7bdc4'
infoblock = p.getblock(hash)
print(infoblock['difficulty'])
我可能需要将HTTP_TIMEOUT = 30
更改为其他内容—从库rpc.py:
...
HTTP_TIMEOUT = 30
class JSONRPCException(Exception):
def __init__(self, rpc_error):
super(JSONRPCException, self).__init__('msg: %r code: %r' %
(rpc_error['message'], rpc_error['code']))
self.error = rpc_error
class RawProxy(object):
# FIXME: need a CChainParams rather than hard-coded service_port
def __init__(self, service_url=None,
service_port=8332,
btc_conf_file=None,
timeout=HTTP_TIMEOUT,
_connection=None):
....
由于
HTTP_TIMEOUT
的值只是作为RawProxy.__init__
方法的timeout
参数的默认值,您可以简单地将所需的超时指定为类实例化的参数,例如:相关问题 更多 >
编程相关推荐