I have written a python script to parse a xml file. I'm calling this file from C# project. But when running a program I'm getting error: No Module named xml.etree.cElementTree.
Program.cs
-----------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IronPython.Hosting;
using IronPython.Modules;
namespace RunExternalScript
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press enter to execute the python script!");
Console.ReadLine();
var py = Python.CreateEngine();
try
{
py.ExecuteFile("wg.py");
}
catch (Exception ex)
{
Console.WriteLine(
"Oops! We couldn't execute the script because of an exception: " + ex.Message);
}
Console.WriteLine("Press enter to exit...");
Console.ReadLine();
}
}
}
wg.py
-----
import xml.etree.cElementTree as ET
tree = ET.parse('Wg.xml')
root = tree.getroot()
childrens = root.getchildren()
for p in root.findall('WGTemplate'):
name = p.find('TemplateName').text
# print(name)
loc = p.find('Filename').text
# print(loc)
for p1 in p.findall('Product'):
print("{:<50}{:<50}{:>50}".format(name, loc, p1.text))
Note: There is no folder or file with name 'xml'
set your python path, to know your system path in .py file just type
and with this you will get your sys path and set those all path in
i hope my answer help you to solve your problem.