ImportError:Jython中没有名为etree的模块

时间:2017-09-17 11:53:40

标签: python python-2.7 ibm-midrange jython-2.5

我正在尝试解析文本文件并将其转换为xml文件。
为此,我得到了一个代码( python3 ),它在我的Windows机器上成功执行 但是,当我想在我的AS400机器上执行相同的代码时,jython会抛出错误:

Traceback (innermost last):        
  File "<string>", line 2, in ?    
ImportError: No module named etree

这是在Windows上为我工作的python脚本。

请帮助我如何解决此问题。

Python代码:

import re
import xml.etree.ElementTree as ET
from contextlib import contextmanager
import sys
rex = re.compile(r'''(?P<title>Web\s+Name
                       |Context\s+Root
                       |Status

                       )
                     \s*:?\s*
                     (?P<value>.*)
                     ''', re.VERBOSE)

root = ET.Element('root')
root.text = '\n'    # newline before the celldata element

with open('WasContent.txt') as f:

    celldata = ET.SubElement(root, 'celldata')
    celldata.text = '\n'    # newline before the collected element
    celldata.tail = '\n\n'  # empty line after the celldata element
    for line in f:
        # Empty line starts new celldata element (hack style, uggly)
        if line.isspace():
            celldata = ET.SubElement(root, 'celldata')
            celldata.text = '\n'
            celldata.tail = '\n\n'

        # If the line contains the wanted data, process it.
        m = rex.search(line)
        if m:
            # Fix some problems with the title as it will be used
            # as the tag name.
            title = m.group('title')
            title = title.replace('&', '')
            title = title.replace(' ', '')

            e = ET.SubElement(celldata, title.lower())
            e.text = m.group('value')
            e.tail = '\n'

# Display for debugging
#ET.dump(root)

# Include the root element to the tree and write the tree
# to the file.
#tree = ET.ElementTree(root)
            tree = ET.ElementTree(root)
#tree.write('cell.xml', encoding='utf-8', xml_declaration=True)
            tree.write('cell.xml', encoding='utf-8', xml_declaration=Tru

我正在阅读的文字档案输入:

  

-------------------------------------检查websphere应用程序状态   -------------------------------------- WASX7209I:已连接到节点SRVR_SRVR上的“SERVER1”进程SOAP连接器;过程的类型   是:UnManagedProcess
  + ---------------------------- +

状态:已停止
  + ---------------------------- +
  + ---------------------------- +
CtxRootForWebMod:指定Web模块的上下文根

     

在Web模块中配置上下文根的值。
Web模块:   SessionTest.war
URI:SessionTest.war,WEB-INF / web.xml
上下文   根:/ aaa
状态:运行
  + ---------------------------- +
  + ---------------------------- +
CtxRootForWebMod:指定Web模块的上下文根

     

在Web模块中配置上下文根的值。

Web   module:WebApp
URI:   MainApp_934v123_20150605.war,WEB-INF / web.xml
上下文根:   / mainapp_icilif
状态:已停止
  + ---------------------------- +
  + ---------------------------- +

输出:

<?xml version='1.0' encoding='utf-8'?> <root>

<celldata> <webmodule>SessionTest.war</webmodule> <contextroot>/aaa</contextroot> <status>Running</status> </celldata>

<celldata> <webmodule>MainApp_934v123_20150605.war</webmodule> <contextroot>/mainapp_icilif</contextroot> <status>Stopped</status> </celldata>


</root>

0 个答案:

没有答案