【发布时间】:2013-10-27 10:35:59
【问题描述】:
我正在尝试在 python 中创建一个带有格式的查询,我不知道如何对数据的二进制输入进行字符串转义。它返回如下内容:
插入
python.UDP(Packet,Destination,Source,Protocol,Version,Header_Length,TTL,Target, @98765433@@, @98765433@@, 987654332@,Destination_Port,Length) 值 (NULL, '00:0C:29:B2:14:0C', '192.168.178.50', '8', '4', '20', '128' , '17', '192.168.178.24', '52371', '8888', '29227', 'b'数据\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00'');)
如何在 python 中通过格式化正确地转义二进制字符串值?
def setopUDP(destination, source, protocol, version, header_length, ttl, protocolEGP, target, source_port, destination_port, length, data):
query = ("INSERT INTO `python`.`UDP` (`Packet`, `Destination`, `Source`, `Protocol`, "
"`Version`, `Header_Length`, `TTL`, `Protocol_UDP`, `Target`, `Source_Port`, "
"`Destination_Port`, `Length`) VALUES (NULL, '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}');)"
.format(destination, source, protocol, version, header_length, ttl, protocolEGP, target, source_port, destination_port, length, data))
setopCON(query)
【问题讨论】:
-
你用的是什么数据库适配器?
标签: python string python-3.x formatting escaping