What do double parentheses mean in a function call? e.g. func(stuff)(stuff)?

后端 未结 3 1069
悲哀的现实
悲哀的现实 2020-12-30 01:19

Original title:

"Help me understand this weird Python idiom? sys.stdout = codecs.getwriter(\'utf-8\')(sys.stdout)"

3条回答
  •  没有蜡笔的小新
    2020-12-30 01:28

    codecs.getwriter('utf-8') returns a class with StreamWriter behaviour and whose objects can be initialized with a stream.

    >>> codecs.getwriter('utf-8')
    
    

    Thus, you are doing something similar to:

    sys.stdout = StreamWriter(sys.stdout)
    

提交回复
热议问题