Applications of Python

import xml.dom.minidom
import os
import sys
import zipfile
import shutil
import datetime
from os import path

def main():
    #working with xml
    doc=xml.dom.minidom.parse("samplexml.xml");
    print doc.nodeName

    print doc.childNodes
    print doc.firstChild.tagName

    skills = doc.getElementsByTagName("skill")
    print("%d skill " %  skills.length)
    counter = 0
    for skill in skills:
        counter +=1
        print "Skill # ",counter,"-",skill.getAttribute("name")

    newSkill=doc.createElement("skill")
    newSkill.setAttribute("name","JavaScript")
    doc.firstChild.appendChild(newSkill)

    skills = doc.getElementsByTagName("skill")
    print ("%d Skill  " % skills.length)
    for skill in skills:
        print skill.getAttribute("name")

    xmlfile = "samplexml.xml"
    fh = open(xmlfile)
    counter = 0
    for line in fh:
        counter +=1
        if line.startswith(" 1 :
    print "there are " ,len(sys.argv) -1 ,'arguments'
    for arg in sys.argv[1:]:
        print arg
else:print "there are no argument"
# checking host platform
print sys.platform   # win32
if sys.platform=="win32":
    import ntpath
    pathmodule = ntpath
print pathmodule   # out put 
#redirect output
old  = sys.stdout
sys.stdout=open("output.txt",'w')
print "this file should be print into file output.txt"
sys.stdout=old
print "come back "

转载于:https://www.cnblogs.com/TendToBigData/p/10501251.html

你可能感兴趣的:(python,javascript)