【发布时间】:2020-08-05 23:51:22
【问题描述】:
所以我有以下我称之为 DecisionCat 的 python 脚本。
import xml.etree.ElementTree as ET
import collections
from dataclasses import dataclass
def LoadStructure(filePath):
tree = ET.parse(rulePath)
root = tree.getroot()
for RuleN in root.findall("Rule"):
NewRule=Rule()
RNumber=RuleN.attrib['RuleNumber']
parameters={}
for child in RuleN:
if(child.tag == "Rule_Name"):
RName=child.text
if(child.tag == "Category"):
RCat=child.text
if(child.tag == "Description"):
RDesc=child.text
if(child.tag=="Script_Object"):
RPath=child.text
if(child.tag == "Parameter_List"):
PName=""
PType=""
for Parameters in child:
if (Parameters.tag == "Parameter"):
for Params in Parameters:
if (Params.tag == "Parameter_Name"):
PName=Params.text
if (Params.tag == "Parameter_Type"):
PType=Params.text
parameters[PName]=PType
NewRule.RuleName=RName
NewRule.RuleCat=RCat
NewRule.RuleDescription=RDesc
NewRule.RulePath=RPath
NewRule.Parameterlist=parameters
catalog[RNumber]=NewRule
class Rule:
RuleName: str
RuleCat: str
RuleDescription: str
RulePath: str
Parameterlist:{}
我已经建立了一个包含以下内容的文件夹结构。
DecisionCatalog (folder)
with DecisionCat (folder)
with __init__.py
DecisionCat.py
这是我的测试脚本。
import sys
import DecisionCatalog
RNumber=""
RName=""
RCat=""
RDesc=""
RPath=""
catalog={}
rulePath="../DC_Extension_v6.xml"
LoadStructure(rulePath)
我收到以下错误消息:
Traceback(最近一次调用最后一次): 文件“TestCat2.py”,第 11 行,在 加载结构(规则路径) NameError: 名称“LoadStructure”未定义
谁能帮忙?
【问题讨论】:
-
你的测试脚本在哪里?
标签: python python-3.x sys traceback