Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

python ÖÐminidom½âÎöxml

python ÖÐminidom½âÎöxml
2009Äê06ÔÂ26ÈÕ ÐÇÆÚÎå 08:40
ÏÂÃæÖ»ÁгöһЩ³£Óõķ½·¨ÊôÐÔ£¬Èç¹ûÒª²é¿´¸ü¶àµÄ·½·¨£¬ ¿ÉÒÔÈ¥¿´ÎļþminidomÈçºÎʵÏֵġ£
»ñµÃDocument¶ÔÏó
·¨Ò»£º
import xml.dom.minidom as m_dom
doc1 = m_dom.getDOMImplementation().createDocument(None, "root1", None)
doc1.documentElement.toxml(encoding="utf-8")
'<root1/>'
·¨¶þ£º
s = "<node><xxxx/></node>"
doc2 = m_dom.parseString(s)
print doc2.toprettyxml(indent="    ", newl="\n", encoding="utf-8")
<?xml version="1.0" encoding="utf-8"?>
<node>
    <xxxx/>
</node>
»ñµÃ¸ú½Úµã£º
rt = doc1.documentElement
´´½¨½Úµã£º
node1 = doc1.createElement("node1")
rt.appendChild(node1)
rt.toxml()
'<root1><node1/></root1>'
ÉèÖÃ/»ñµÃÊôÐÔ£º
node1.setAttribute("name", "name1")
rt.toxml()
'<root1><node1 name="name1"/></root1>'
node1.getAttribute("name")
'name1'
´´½¨Êý¾Ý½Úµã£º
dt = doc1.createTextNode("the datas.")
node1.appendChild(dt)
rt.toxml()
'<root1><node1 name="name1">the datas.</node1></root1>'
node1.firstChild.toxml()
'the datas.'
»ñµÃ×ӽڵ㣺
node1
<DOM Element: node1 at 0xed0aa8>
rt.childNodes
[<DOM Element: node1 at 0xed0aa8>]
rt.getElementsByTagName("node1")
[<DOM Element: node1 at 0xed0aa8>]
rt.firstChild
<DOM Element: node1 at 0xed0aa8>
node2 = doc1.createElement("node2")
rt.appendChild(node2)
<DOM Element: node2 at 0xe890a8>
rt.toxml()
'<root1><node1 name="name1">the datas.</node1><node2/></root1>'
rt.childNodes
[<DOM Element: node1 at 0xed0aa8>, <DOM Element: node2 at 0xe890a8>]
node1.firstChild
<DOM Text node "the datas.">
ɾ³ý×ӽڵ㣺
n2 = rt.childNodes[1]
rt.removeChild(n2)
<DOM Element: node2 at 0xe890a8>
rt.toxml()
'<root1><node1 name="name1">the datas.</node1></root1>'
node1.removeChild(node1.firstChild)
<DOM Text


Ïà¹ØÎĵµ£º

Python ¿½±´¶ÔÏó£¨É±´deepcopyÓëdz¿½±´copy£©

>>> import copy
>>> a = [1,2,3,4,['a','v']]
>>> b = a
>>> b
[1, 2, 3, 4, ['a', 'v']]
>>> c = copy.copy(a)
>>> c
[1, 2, 3, 4, ['a', 'v']]
>>> d = copy.deepcopy(a)
>>> d
[1, 2, 3, 4, ['a', 'v']]
>>> a.append(5) ......

PythonÎļþ²Ù×÷


Îļþ²Ù×÷ÊdzÌÐòÉè¼ÆÖв»¿É»òȱµÄÖØÒª²¿·Ö¡£Pythonͨ¹ýÒ»¸öÄÚÖú¯ÊýopenÀ´´ò¿ªÎļþ¡£
     open(filename,mode,buffer)
     ÆäÖеÚÒ»¸ö²ÎÊýÊÇÒª´ò¿ªµÄÎļþµÄÎļþÃû£¬±ØÑ¡£»µÚ¶þ¸öÊÇ´ò¿ª·½Ê½£¬¿ÉÑ¡£»µÚÈý¸öΪ»º³åÇø£¬¿ÉÑ¡¡£Ä¬ÈÏÇé¿öÏÂÊÇÒÔ“¶Á”ģʽ´ò¿ªÎļþ¡£¸Ãº¯Êý ......

Python½Å±¾½âÎöBitTorrentÖÖ×ÓÎļþÄÚÈÝ

ÓкܶàÖÖ×ÓÎļþ£¬ÓÐʱºò¼Ç²»ÇåÀïÃ涼ÊÇʲô¶«Î÷£¬ÓÖ²»ÏëÒ»¸öÒ»¸öµÄÍϷŵ½Ñ¸À×»òBTÈí¼þÀïÍ·¿´£¬
ÉÏÍø²éÁËÒ»ÏÂPythonµÄ½Å±¾£¬×Ô¼ºÒ²ÉÔ΢ÐÞ¸ÄÁËһϣ¬´úÂëÈçÏ£¬Õ³Ìùµ½Îı¾±à¼­Æ÷ÖУ¨×îºÃÊÇ´ø¸ñʽµÄÈçUltraEdit»òVS2008µÈ£©£º
±£´æ³Épyºó׺µÄ£¬Ö±½ÓÔËÐÐ
import re
def tokenize(text, match=re.compile("([idel])|(\d+):|( ......

ÈçºÎ·¢²¼vcµ÷ÓÃPythonµÄ¶ÀÁ¢ÔËÐеijÌÐò

±àÒëPython½Å±¾Éú³É¿ÉÖ´ÐгÌÐò£¬¿ÉÒÔͨ¹ýpy2exe±àÒëÍê³É¡£
ÔÚVCÖе÷ÓÃpythonʱ£¬¿ÉÒÔ½áºÏpy2exe£¬Íê³ÉÕû¸ö³ÌÐòµÄ¶ÀÁ¢·¢²¼^_^
google.py:
#! /usr/bin/env python
import sys, webbrowser
def main(a):
    url = "http://www.google.com/search?q=%s" % a
    webbrowser.o ......

python ¶ÁдExcelÎļþ

http://sourceforge.net/projects/pyexcelerator/
12ÔÂ2ÈÕ
python ¶ÁдExcelÎļþ£¨×ªÌû limodou£©
http://www.lexicon.net/sjmachin/xlrd.htm
Õâ¸ö°üÊÇÓÃÀ´¶ÁExcelÎļþµÄ
ÔÚ·¢ÏÖ xlrd Ö®ºó²»¾Ã¾Í·¢ÏÖÁË pyExcelerator
£¬ËüÓë xlrd ²»Í¬£¬ËüÖ÷ÒªÊÇÓÃÀ´Ð´ Excel Îļþ£¬µ±È»¶ÁÒ²ÊÇûÓÐÎÊÌâµÄ¡£ÏÂÃæ¾ÍËüµÄʹÓüòµ¥µØ½éÉ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ