made a silly error:
xml is a string containing the xml doc.
but its name clashes with the xml.dom.minidom package
xmldom = xml.dom.minidom.parseString(xml_string)
xml processing:
using multiple line for code. use "\"
eg.:
xmldom = xml.dom.minidom.parseString(xml)
xml is a string containing the xml doc.
but its name clashes with the xml.dom.minidom package
xmldom = xml.dom.minidom.parseString(xml_string)
xml processing:
elements = xmldom.getElementsByTagName("mytag")
print elements.length # return number of elements
element.getAttribute("myattr")
using multiple line for code. use "\"
eg.:
print "this, " + "that, " \
+ "those"
Dictionary
mydictionary = {"mykey":"hehe"}
mydictionary["newkey"] = "hello" # can be number too
for k, v in mydictionary.iteritems():
print k + "= " + v
if "key" in mydictionary:
print "key exists in dictionary"
Socket client:
import socket
socket = socket(AF_INET, SOCK_STREAM)
socket.connect(("127.0.0.1", 5000)) # address and port
data = socket.recv(4096) # 4096 bytes buffer
binary data
data = bytearray(socket.recv(4096))
size = (data[3]<<24 | data[2]<<16 | data[1]<<8 | data[0] ) # to 32-bit or 4 byte integer
No comments:
Post a Comment