最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Why can a python class using pygame's Vector2 as a parent not have an attribute name starting with x or y? - Stack Overf

programmeradmin1浏览0评论

This is really weird, but I'm making a custom vector using pygame's Vector2 as a parent, and any attempt to define an attribute that starts with the letters x or y results in an error upon initialization. If the x is anywhere else in the attribute name, it works fine.

For example, this works fine:

class CustomVector(pygame.Vector2):
    def __init__(self,vector,attribute):
        super().__init__(vector)
        self.attribute = attribute

CustomVector((0,0),True)

This also works fine:

class CustomVector(pygame.Vector2):
    def __init__(self,vector,attribute):
        super().__init__(vector)
        self.attributex = attribute

CustomVector((0,0),True)

But this raises an error:

class CustomVector(pygame.Vector2):
    def __init__(self,vector,attribute):
        super().__init__(vector)
        self.xattribute = attribute

CustomVector((0,0),True)

The error raised is generally TypeError: a sequence is expected, but I've gotten others

Per John Gordon, here is the whole error message. There is another error, but it is clearly stated that it is the direct result of the TypeError:

TypeError: a sequence is expected

The above exception was the direct cause of the following exception:


Traceback (most recent call last):


File "c:\Users\ajhom\Documents\Monster\code\test.py", line 14, in <module>
CustomVector((0,0),True)
~~~~~~~~~~~~^^^^^^^^^^^^
SystemError: <function CustomVector.__init__ at 0x000002B7C347EDE0> returned a result with an exception set

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论