我是python的新手所以请忽略,如果这是愚蠢的。在这里,我在以某种指定格式打印数据时获得无效语法。
with open("ip_services.xyz", "w") as handle:
for service in sorted(...some functionality...)):
print("ip_server(\"{}\", {}, {}, {}, {}, {}, {}) # {}, {}".format(
service.address, service.port, 1 if service.udp else 0,
service.service_id, service.instance_id,
service.major_version, service.minor_version,
service.xyz,
service.service_name),
file=handle)
错误就像: -
File "producer.py", line 220
print("{} = \"{}\" # {}".format(signal, value, label), file=handle)
^
SyntaxError: invalid syntax