问题
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