# main.pyimport sysfrom PySide6.QtWidgets import QApplicationfrom PySide6.QtCore import QByteArrayfrom compareYamlFile.compareYamlFile import CompareYamlFilefrom commonLib.udpComm.udpComm import UdpCommfrom commonLib.jsonHelper.jsonHelper import JsonHelperdef handle_received(data: QByteArray, host, port):text = data.data().decode("utf-8", errors="ignore")print(f"[主程序回调] 接收到数据: {text} 来自 {host.toString()}:{port}")def test_json():data = {"name": "绅纺西","port": 12345,"list": [1, 2, 3],"nested": {"a": 10, "b": True}}# 编码为字符串json_str = JsonHelper.encode(data)print("编码后JSON字符串:")print(json_str)# 解析回对象parsed = JsonHelper.decode(json_str)print("解析后Python对象:")print(parsed)# 写入文件JsonHelper.write_file(data, "test.json")# 从文件读取read_back = JsonHelper.read_file("test.json")print("从文件读回的内容:")print(read_back)def main():test_json();udp = UdpComm();udp.bind();udp.dataReceived.connect(handle_received)udp.send_data(b"Hello from main.py", "127.0.0.1", 12345)comparer = CompareYamlFile()file1 = "./cfg/config.yaml" # 你第一个yaml文件路径file2 = "./cfg/config1.yaml" # 你第二个yaml文件路径try:diffs = comparer.compare_files(file1, file2)if diffs:print("发现差异项:")for key, val in diffs.items():print(f"{key}:")print(f" file1 = {val['file1']}")print(f" file2 = {val['file2']}")else:print("两个文件内容完全一致。")except Exception as e:print(f"比较时发生错误: {e}")if __name__ == "__main__":app = QApplication(sys.argv)main()sys.exit(app.exec())
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。