Can you use map to create instances without a wrapper?

后端 未结 3 1440
半阙折子戏
半阙折子戏 2021-01-21 01:56

In Python, you can give the name of a class as an argument to map in order to create instances of that class:

class Point(object):
    def __init__(         


        
3条回答
  •  太阳男子
    2021-01-21 02:21

    I think your conclusion is correct: init isn't being treated as a conventional func. You might want to report this as a bug; I'm not sure if this is intended behavior or not.

    BTW, a more concise way to achieve what you want is:

    coords.map{ p => Point(x: p[0], y: p[1]) }
    

提交回复
热议问题