Python:有没有办法在导入的库中更改值?

2024-09-29 23:30:20 发布

您现在位置:Python中文网/ 问答频道 /正文

如果我从库中导入一个类,而这个类使用的变量/常量是在库中定义的,但是在类之外,我可以更改这个值吗?你知道吗

我正在写剧本:

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):
....

Tags: selfnonehttpinitdefservicetimeoutcode

热门问题