Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2304745
  • 博文数量: 321
  • 博客积分: 3440
  • 博客等级: 中校
  • 技术积分: 2992
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-24 09:08
个人简介

我就在这里

文章分类

全部博文(321)

文章存档

2015年(9)

2014年(84)

2013年(101)

2012年(25)

2011年(29)

2010年(21)

2009年(6)

2008年(23)

2007年(23)

分类: Python/Ruby

2013-02-19 08:18:21

# encoding:GBK
from xml.dom.minidom import Document
# from xml.etree.ElementTree import ElementTree
import time
class XmlBuild:
    def __init__(self, action_id, operation):
        self.action_id = action_id
        self.operation = operation
        self.parameter = None
        self.commandname = None
        self.doc = Document()

        


调用

'''
Created on 2013-2-19


@author: lvxinzhi
'''
import XmlBuild
import Send


if __name__ == '__main__':
    xml = XmlBuild.XmlBuild('ClientFileManagerCommand', 'downloadfile')
    xml.addParameter('filename', 'update_tmp.ini')
    xml.commandname = 'ClientFileManagerCommand.downloadfile'
    print xml.getXml().toxml()
    #xml.saveas('c:\\client.ClientFileManagerCommand.downloadfile.xml')
    


Traceback (most recent call last):
  File "D:\workSpace\python\Client\src\Main.py", line 10, in
    xml = XmlBuild('ClientFileManagerCommand', 'downloadfile')
TypeError: 'module' object is not callable


原因分析:
Python导入模块的方法有两种:import module 和 from module import,区别是前者所有导入的东西使用时需加上模块名的限定,而后者不要。
正确的代码:
import XmlBuild
import Send
if __name__ == '__main__':
    xml = XmlBuild.XmlBuild('ClientFileManagerCommand', 'downloadfile')


from XmlBuild import *
import Send
if __name__ == '__main__':
    xml = XmlBuild('ClientFileManagerCommand', 'downloadfile')

阅读(1138) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~