方括号后加大括号表示类方法中的谁?

2024-10-01 15:40:10 发布

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

我不懂这个密码?括号[]在定义或词典之后是什么意思(请参阅以cert\u verify开头的行)

我运行过谷歌。很多很多。抱歉我的英语不太好

from urllib.parse import urlparse
import requests.adapters
from exchangelib.protocol import BaseProtocol

class RootCAAdapter(requests.adapters.HTTPAdapter):
    # An HTTP adapter that uses a custom root CA certificate at a hard coded location
    def cert_verify(self, conn, url, verify, cert):
        cert_file = {
            'example.com': '/path/to/example.com.crt',
            'mail.internal': '/path/to/mail.internal.crt',
        }[urlparse(url).hostname]
        super(RootCAAdapter, self).cert_verify(conn=conn, url=url, verify=cert_file, cert=cert)

# Tell exchangelib to use this adapter class instead of the default
BaseProtocol.HTTP_ADAPTER_CLS = RootCAAdapter

Tags: tofromimporthttpurlcertconnrequests
1条回答
网友
1楼 · 发布于 2024-10-01 15:40:10

它正在查找以前定义的词典。即

>>> result = {'a':1234, 'b':'hello'}['a']
>>> print(result)
1234
>>> result = {'a':1234, 'b':'hello'}['b']
>>> print(result)
hello

继续和谷歌一起跑。或是小鸭快走

相关问题 更多 >

    热门问题