Ich habe dieses "Programm", das mit Google Protobufs funktioniert. Beim Erstellen von Python -Code aus dem gegebenen Compiler (Protoc) heißt es immer "Nicht bearbeiten!". Ich bearbeite den generierten Code also nicht und ich möchte nicht wirklich (es muss eine Lösung geben, ohne jede Datei selbst zu beheben, wenn der Code generiert wird).|root:
|---protos:
| |---API:
| | |---protoApiA.proto
| | |---protoApiB.proto ...
| |---common:
| |---protoCommonA.proto ...
|---src:
| |---__init__.py
| |---foo:
| | |---__init__.py
| | |---bar:
| | | |---main.py
| | | |---protos:
| | | | |---API:
| | | | | |---protoApiA_pb2.py
| | | | | |---protoApiB_pb2-grpc.py ...
| | | | |---common:
| | | | | |---protoCommonA_pb2.py
| | | | | |---....
|---test_script.py
< /code>
Protoapia.Proto Importe von protocommona.proto. < /p>
import "common/protoCommonA.proto";
< /code>
, der sich in: < /p>
auflöstfrom common import protoCommonA_pb2 as common_dot_protoCommonA__pb2
< /code>
Nachdem ich sie mit der folgenden PowerShell -Eingabeaufforderung erstellt habe: < /p>
& py -3.10 -m grpc_tools.protoc -I./protos --python_out=./src/foo/bar/protos/ --grpc_python_out=./src/foo/bar/protos/ common/protoCommonA.proto API/protoApiA.proto API/protoApiB.proto
< /code>
So weit so gut. Hier ist, was die Init -Dateien enthalten: < /p>
# root/src/__init__.py:
from . import foo
# root/src/foo/__init__.py:
from .bar.main import ... #relevant functions for test_script.py
< /code>
Die Datei main.py muss die Proto-Dateien für einige GRPC-verwandte Dinge verwenden. Bescheid über protocommona_pb2.py.>
Importe mit GRPC richtig abrufen ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post