Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
I create code in C# with implement Py code using IronPython. But I have this problems:

I have code in PY (MainFile.py at first row)
Python
import My_H as my_h

My_H.py contain only more constant of dictionary like
Python
My_STATE = {
            'My_UP': 1,
            'My_SB': 2,
            'My_PF': 3,
            }

I have a code in C# (VS 2013 C# + PTVS 2.1 VS 2013.msi + IronPython 2.7.5)
C#
ScriptEngine engine = Python.CreateEngine();
engine.SetSearchPaths(new string[] { myPath });
ScriptSource source = engine.CreateScriptSourceFromFile("MainFile.py");
ScriptScope scope = engine.CreateScope();
source.Execute(scope); <--- exception

and source.Execute in C# give this exception:
MissingMemberException was unhandled - LightException object has no attribute My_H

and second exception is in Python program. (This program code was created in PyDev and was right).
But when I run Python code from (VS 2013 Python + PTVS 2.1 VS 2013.msi + IronPython 2.7.5) this code give me a exception
Python
import xml.sax
parser = xml.sax.make_parser( ) <--- exception 

"No parsers found"
when I look in VS in debug mode I see xml is module 'xml' from 'C:\Program Files (x86)\IronPython 2.7\Lib\xml\__init__.py'
and this module contain Function (function make_parser at 0x0000000000000042)
I found some solution for this exception, but not work for me http://ironpython.codeplex.com/workitem/31361[^]

Thank you
Posted
Updated 14-Jan-15 2:21am
v5
Comments
Richard MacCutchan 14-Jan-15 7:46am    
The code you have shown bears no realtion to the problems you are reporting. Please edit your question and add the relevant detail.
Richard MacCutchan 14-Jan-15 10:19am    
The exception refers (probably) to some code in MainFile.py, so you need to show that code.
smoula99 15-Jan-15 2:07am    
Hi
This file have about 1000rows code. I import My_H where I have dictionary, and MainFile.py a many time call value from dictionary like:
my_h.My_STATE['My_UP']

Problem is in C#, because I run MainFile from (VS 2013 Python + PTVS 2.1 VS 2013.msi + IronPython 2.7.5) - everything is OK
Problem is only when I run code using C# and IronPython (using code show above, ScriptEngine engine....)

In your main file you have an import that renames your type:
Python
import My_H as my_h

somewhere else you get the error:
MissingMemberException was unhandled - LightException object has no attribute My_H

So you have declared your import as my_h but referred to it as My_H , which is incorrect. You need to change it so both are the same.
 
Share this answer
 
Comments
smoula99 15-Jan-15 1:58am    
Hi
I don't think your proposal is right because on another forum is used
from System.Windows import WindowState as WindowState1
After "as" can by used whatever how alias name

http://stackoverflow.com/questions/21857875/ironpython-import-two-enums-with-the-same-name
Richard MacCutchan 15-Jan-15 4:42am    
Did you try it?
smoula99 16-Jan-15 3:06am    
I have functional program created in PyDev. I thought when is OK in PyDev and program working - than must working in IronPyton too?
When I run program VS 2013 Python + PTVS 2.1 VS 2013.msi + IronPython 2.7.5 - program working, but when I run in VS 2013 C# + PTVS 2.1 VS 2013.msi + IronPython 2.7.5 - using DLL from IronPython - program not working.
I was hopeless, but I found solution for my second exeption in (VS 2013 Python + PTVS 2.1 VS 2013.msi + IronPython 2.7.5)
Solution was very easy on this site
https://github.com/IronLanguages/ironclad/wiki/building
(only copy two file - then parser working)

VB
$ copy "c:/Python27/lib/xml/dom/expatbuilder.py" "c:/Program Files (x86)/IronPython 2.7/lib/xml/dom"
$ copy "c:/Python27/lib/xml/sax/expatreader.py" "c:/Program Files (x86)/IronPython 2.7/lib/xml/sax"


I must find only one solution for first exection.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900