سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top