Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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×Ö·û´®µÄencodeÓëdecode


Ê×ÏÈÒª¸ãÇå³þ£¬×Ö·û´®ÔÚPythonÄÚ²¿µÄ±íʾÊÇunicode±àÂ룬Òò´Ë£¬ÔÚ×ö±àÂëת»»Ê±£¬Í¨³£ÐèÒªÒÔunicode×÷ΪÖмä±àÂ룬¼´ÏȽ«ÆäËû±àÂëµÄ×Ö·û´®½âÂ루decode£©³Éunicode£¬ÔÙ´Óunicode±àÂ루encode£©³ÉÁíÒ»ÖÖ±àÂë¡£
decodeµÄ×÷ÓÃÊǽ«ÆäËû±àÂëµÄ×Ö·û´®×ª»»³Éunicode±àÂ룬Èçstr1.decode('gb2312')£¬±íʾ½«gb2312±àÂëµÄ×Ö·û´®×ª» ......

ÈçºÎ·¢²¼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¼òµ¥µÄ¿ÉÄæ¼ÓÃܳÌÐò

¼òµ¥¼ÓÃÜ£¬ÓÃpythonÀ´Ð´Ð´¡£
#coding=utf-8
'''
Description: ¿ÉÄæµÄ¼ÓÃÜÓë½âÃÜ
Environment: python2.5.x
Author:idehong@gmail.com
'''
import os
import sys
class Code(object):
'''¿ÉÄæµÄ¼ÓÃÜÓë½âÃÜ'''

def __init__(self, key = "idehong@gmail.com"):
self.__src_key ......

python ¶ÁдExcelÎļþ

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

Óà python ¿ìËÙ´î½¨ÍøÓηþÎñÆ÷

ÀµÓºƣ¨http://laiyonghao.com£©
½ñÌ죨2009Äê5ÔÂ31ÈÕ£© OurPNP.org ¸ãÁ˸ö¾Û»á»î¶¯£¬ÅªÁËÊ®¼¸¶þÊ®¸öÈËÔÚ¹ãÖݺ£Öé¹ã³¡µÄÌûá´ôÁËÎå¸öСʱ£¬´´ÏÂÁËÎÒÔÚ K ·¿´ôµÄ×ʱ¼ä¼Í¼¡£Ó¦ËûÃǵÄÑûÇ룬ÎÒ×öÁ˸öÌâΪ¡¶Óà python ¿ìËÙ´î½¨ÍøÓηþÎñÆ÷¡·µÄСÑݽ²£¬ÒòΪÄDZߵĵçÊÓ¾¹È»²»ÄܽӵçÄÔ£¬ËùÒÔ½²µÄʱºòûÓÐÄܹ»²ÎÕÕ PPT À´½²£¬¹Û ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ