V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
dawnzhu
V2EX  ›  程序员

Python 中 super 用法

  •  
  •   dawnzhu · 64 天前 · 1356 次点击
    这是一个创建于 64 天前的主题,其中的信息可能已经有所发展或是发生改变。
    class PooledDatabase(object):
        def __init__(self, database, max_connections=20, stale_timeout=None,
                     timeout=None, **kwargs):
            self._max_connections = make_int(max_connections)
            self._stale_timeout = make_int(stale_timeout)
            self._wait_timeout = make_int(timeout)
            if self._wait_timeout == 0:
                self._wait_timeout = float('inf')
    
            self._pool_lock = threading.RLock()
    
            # Available / idle connections stored in a heap, sorted oldest first.
            self._connections = []
    
            # Mapping of connection id to PoolConnection. Ordinarily we would want
            # to use something like a WeakKeyDictionary, but Python typically won't
            # allow us to create weak references to connection objects.
            self._in_use = {}
    
            # Use the memory address of the connection as the key in the event the
            # connection object is not hashable. Connections will not get
            # garbage-collected, however, because a reference to them will persist
            # in "_in_use" as long as the conn has not been closed.
            self.conn_key = id
    
            super(PooledDatabase, self).__init__(database, **kwargs)
    

    这里这种用法正确么? super(PooledDatabase, self).init(database, **kwargs)

    2 条回复    2024-10-26 16:12:15 +08:00
    NoOneNoBody
        1
    NoOneNoBody  
       64 天前   ❤️ 1
    语法没有错误,意义就要看应该放在哪一行
    iorilu
        2
    iorilu  
       64 天前
    这是老版本用法

    现在只用 super().__init__()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   904 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 20:02 · PVG 04:02 · LAX 12:02 · JFK 15:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.