小编Gro*_*247的帖子

Python protobuf“来自google.protobuf.pyext import _message”-“ ImportError:DLL加载失败:找不到指定的过程”

我正在尝试获取一个简单的Python脚本,以将protobuf文件转换为json文件(我在工作中所需要的格式)。

我已经看到了一些建议,可以升级或降级google.protobuf,以升级到Python 3.6.1(我在3.6.0)。两种解决方案均无济于事。

def convert_to_json(directory: str):

    os.chdir(jsonPath)

    for (root, dirs, files) in os.walk(os.getcwd()):

        for file_ in files:

            if os.path.dirname(file_) != root and file_.endswith(".pb"):

                json_file: str = MessageToJson(file_)

        file_name = (os.path.dirname(file_).split('\\')[-1]) + ".json"
        file_path = os.join(jsonPath, file_name)

        with open(file_path, "w") as new_file:
            new_file.write(json_file)
Run Code Online (Sandbox Code Playgroud)

我希望可以简单地运行它,并将大量的.pb文件(Google字体)转换为.json文件,以便能够对程序中的字体进行分类。

发生的事情是我遇到了以下错误:

Traceback (most recent call last):
  File "[path to pythonfile].py", line 5, in <module>
    from protobuf.json_format import MessageToJson
  File "C:\Python\Lib\site-packages\google\protobuf\json_format.py", line 63, in <module>
    from google.protobuf import descriptor
  File "[pathToVenv]\venv\lib\site-packages\google\protobuf\descriptor.py", line 47, in <module>
    from google.protobuf.pyext import …
Run Code Online (Sandbox Code Playgroud)

python runtime-error protocol-buffers

5
推荐指数
2
解决办法
913
查看次数

如何从__str__方法修复无限循环生成?

File "C:\Users\kevin\Documents\Programs\ParLumen\trait.py", line 76, in __str__
    ret_str = super().__str__()
  File "C:\Users\kevin\Documents\Programs\ParLumen\trait.py", line 39, in __str__
    ret_str += f'{self.name}\n'
RecursionError: maximum recursion depth exceeded
Run Code Online (Sandbox Code Playgroud)

这里有很多很多行,但它只是重复相同的两行,然后最后的不同行是"RecursionError:超出最大递归深度"

我不确定为什么会这样.

以下是导致问题的代码:

from abc import ABC, abstractmethod
from enum import Enum, unique

from parlumen.game import *

# Base Trait class
class Trait(ABC):

    def __init__(self, name, short_desc="No Desc", long_desc=None):
        self.name = name
        # self.value = value # may restrict this with req. 'avail_values()' func

        """
        if short_desc is not "No Desc":
            self.short_desc = short_desc
        """
        self.short_desc = …
Run Code Online (Sandbox Code Playgroud)

python oop recursion loops

1
推荐指数
1
解决办法
51
查看次数

VB - 按下退格键后,TextChanged 没有正确触发?

我的问题归结为:

我有六个文本框,它们期望一个介于 0 和给定数字之间的值。我想要实现的是:

  • 如果输入的数字介于 0 和指定数字之间(作为标签),文本将保持黑色
  • 如果输入的数字超过指定的数字,文本将变为红色

这里的问题是,如果指定的数字是“10”,而用户输入 11,它会变成红色,这是应该的,但是,如果他们按下退格键(输入的数字现在是 1),数字仍然是红色的,即不是预期的功能 - 数字 1 应该是黑色的,因为它介于 0 和指定的数字之间。

所有指定的数字现在都是硬编码的(我正在学习初学者课程,这只是我为了增加程序功能而做的事情,我还没有为每个“作业”添加类" ) 并且您可以在技术上输入负数,我目前不在乎。

这是作为特定 GroupBox 中所有文本框的处理程序添加的子例程

' Handler which gets added to all TextBoxes in "grpGrades" GroupBox
    Private Sub txtGradePoints_TextChanged(sender As Object, e As EventArgs)

        ' Take in generic sender (Textbox) and convert to TextBox (necessary due to Strict mode)
        Dim textBox = CType(sender, TextBox)
        Try
            ' the value of the current TextBox being checked
            Dim val = Decimal.Parse(textBox.Text)
            Select Case textBox.Name
                Case …
Run Code Online (Sandbox Code Playgroud)

vb.net

-1
推荐指数
1
解决办法
167
查看次数