What does it mean to put a dot in a Python class argument?

有些话、适合烂在心里 提交于 2019-12-25 06:43:18

问题


In Python, I saw a class definition as the following:

from protorpc import messages

# Create the request string containing the user's name
class HelloRequest(messages.Message):
    my_name = messages.StringField(1, required=True)

What does messages.Message mean?


回答1:


from protorpc import messages
class HelloRequest(messages.Message):

Is just another way of spelling:

from protorpc.messages import Message
class HelloRequest(Message):

Or even...

import protorpc
class HelloRequest(protorpc.messages.Message):

That is, HelloRequest derives from the Message class in the messages submodule of the protorpc package.




回答2:


Basically, HelloRequest comes from the a class named Message in the messages submodule of a specific group named protorpc. What your calling an argument is not an argument. It simply says that HelloRequest is using messages.Message as its start class.



来源:https://stackoverflow.com/questions/20933050/what-does-it-mean-to-put-a-dot-in-a-python-class-argument

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!