From swpark71 at gmail.com Mon Apr 1 20:00:02 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Mon, 1 Apr 2013 11:00:02 -0700 Subject: [Python.NET] Would you share your idea how to call python command from embedded Python.Net? Message-ID: Hi, I've been played with Python.Net for a week, but I can't find any sample to use Python.Net in embedded way. I've searched many threads from the previous emailing list, the result are not consistent, and looks like no solution ??. What I'm trying to do is that I want to get result (po) from C# code after executing python command such as 'print 2+3' from python prompt. When I executed it from nPython.exe, it prints out 5 as I expected. However, when I run this code from embedded way. it returns 'null' always. Would you give me some thoughts how I can get the execution result? Basically, is this feature one of Python.Net project intended for C#(.Net) to be able to call python commands/scripts? Thank you, Spark. using NUnit.Framework; using Python.Runtime; namespace CommonTest { [TestFixture] public class PythonTests { public PythonTests() { } [Test] public void CommonPythonTests() { PythonEngine.Initialize(); IntPtr gs = PythonEngine.AcquireLock(); PyObject po = PythonEngine.RunString("print 2+3"); PythonEngine.ReleaseLock(gs); PythonEngine.Shutdown(); } } } -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Mon Apr 1 20:08:24 2013 From: brad at fie.us (brad at fie.us) Date: Mon, 1 Apr 2013 14:08:24 -0400 Subject: [Python.NET] Would you share your idea how to call python command from embedded Python.Net? In-Reply-To: References: Message-ID: <9A682B90-62A4-4310-87E8-D28AD5983C8A@fie.us> Yes it is supposed to work. But I'd point out that there is a big difference between the statements: print 2+3 and 2+3 What exactly would you expect to get back as a return from the print statement? On Apr 1, 2013, at 2:00 PM, Seungweon Park wrote: > Hi, > > I've been played with Python.Net for a week, but I can't find any sample to use Python.Net in embedded way. I've searched many threads from the previous emailing list, the result are not consistent, and looks like no solution ??. > > What I'm trying to do is that I want to get result (po) from C# code after executing python command such as 'print 2+3' from python prompt. > > When I executed it from nPython.exe, it prints out 5 as I expected. However, when I run this code from embedded way. it returns 'null' always. Would you give me some thoughts how I can get the execution result? > > Basically, is this feature one of Python.Net project intended for C#(.Net) to be able to call python commands/scripts? > > Thank you, > Spark. > > using NUnit.Framework; > using Python.Runtime; > > namespace CommonTest > { > [TestFixture] > public class PythonTests > { > public PythonTests() > { > > } > [Test] > public void CommonPythonTests() > { > > PythonEngine.Initialize(); > > IntPtr gs = PythonEngine.AcquireLock(); > PyObject po = PythonEngine.RunString("print 2+3"); > PythonEngine.ReleaseLock(gs); > > PythonEngine.Shutdown(); > } > } > } > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet From swpark71 at gmail.com Mon Apr 1 23:02:35 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Mon, 1 Apr 2013 14:02:35 -0700 Subject: [Python.NET] Would you share your idea how to call python command from embedded Python.Net? In-Reply-To: References: <9A682B90-62A4-4310-87E8-D28AD5983C8A@fie.us> Message-ID: Also wrote a simple console application using Python.Net, But PythonEngine.RunString() returns 'null' so I got error. namespace npythontest { class Program { static void Main(string[] args) { PythonEngine.Initialize(); IntPtr gs = PythonEngine.AcquireLock(); PyObject po = PythonEngine.RunString("2+3"); Trace.WriteLine("Python: " + po.ToString()); PythonEngine.ReleaseLock(gs); PythonEngine.Shutdown(); } } } Result is Unhandled Exception: System.NullReferenceException: Object reference not set toan instance of an object. at npythontest.Program.Main(String[] args) in c:\temp\npythontest\npythontest \Program.cs:line 20 I would expect above code will give some result. I think I'm stuck. On Mon, Apr 1, 2013 at 11:32 AM, brad at fie.us wrote: > It's running in process with your .net code. So it's the same standard > output stream. A console's WriteLine() print statement should appear in > the same place. In VS, my recollection is that there is a specific panel > you can bring up in the debugger. Or, your project may be set to spawn an > external console. Depends on your configuration. I don't know NUnit all > that well. It's possible the NUnit's runtime redirects the output stream > somewhere else as well. > > -brad > > On Apr 1, 2013, at 2:29 PM, Seungweon Park wrote: > > Well, would you tell me how to check the console when I execute the > PythonEngine.RunString("print 2+3")? > I'm running the line from VS2012 debugging mode, so I don't know how to > check the python console? > > On Mon, Apr 1, 2013 at 11:23 AM, brad at fie.us wrote: > >> And have you checked the console to see if python is dutifully doing what >> you are asking it to do, which is print "5" to the output stream? That >> will not come back as a return value. You didn't ask it to give you an >> object. You asked it to print 5 to the output console. >> >> On Apr 1, 2013, at 2:21 PM, Seungweon Park wrote: >> >> Hi Brad, >> >> Well, I tried both 'print 2+3' and '2+3', but both returned 'null'. >> I want to have both results of execution. That is, I want to have same >> results whatever nPython.exe gives us. >> >> Thanks, >> Spark. >> >> On Mon, Apr 1, 2013 at 11:08 AM, brad at fie.us wrote: >> >>> Yes it is supposed to work. >>> >>> But I'd point out that there is a big difference between the statements: >>> >>> print 2+3 >>> >>> and >>> >>> 2+3 >>> >>> What exactly would you expect to get back as a return from the print >>> statement? >>> >>> On Apr 1, 2013, at 2:00 PM, Seungweon Park wrote: >>> >>> > Hi, >>> > >>> > I've been played with Python.Net for a week, but >>> I can't find any sample to use Python.Net in >>> embedded way. I've searched many threads from the previous emailing list, >>> the result are not consistent, and looks like no solution ??. >>> > >>> > What I'm trying to do is that I want to get result (po) from C# code >>> after executing python command such as 'print 2+3' from python prompt. >>> > >>> > When I executed it from nPython.exe, it prints out 5 as I expected. >>> However, when I run this code from embedded way. it returns 'null' always. >>> Would you give me some thoughts how I can get the execution result? >>> > >>> > Basically, is this feature one of Python.Net project intended for C#(.Net) to be able to call python commands/scripts? >>> > >>> > Thank you, >>> > Spark. >>> > >>> > using NUnit.Framework; >>> > using Python.Runtime; >>> > >>> > namespace CommonTest >>> > { >>> > [TestFixture] >>> > public class PythonTests >>> > { >>> > public PythonTests() >>> > { >>> > >>> > } >>> > [Test] >>> > public void CommonPythonTests() >>> > { >>> > >>> > PythonEngine.Initialize(); >>> > >>> > IntPtr gs = PythonEngine.AcquireLock(); >>> > PyObject po = PythonEngine.RunString("print 2+3"); >>> > PythonEngine.ReleaseLock(gs); >>> > >>> > PythonEngine.Shutdown(); >>> > } >>> > } >>> > } >>> > >>> > _________________________________________________ >>> > Python.NET mailing list - PythonDotNet at python.org >>> > http://mail.python.org/mailman/listinfo/pythondotnet >>> >>> >> >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From swpark71 at gmail.com Thu Apr 4 17:34:55 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Thu, 4 Apr 2013 08:34:55 -0700 Subject: [Python.NET] I can't run test_engine.py with nPython.exe. Would you tell me why? Message-ID: Hi, I ran every tests from src\tests. However, I can't run runtests.py and test_module.py. test_module.py has an error message in console window and pops up "Python Console" with "Python Console has stopped working" message. Would you tell me what I need to check to run this script? It looks to me having a problem when loading a module. Thanks, Spark. C:\Automation\PythonNet\src\tests>..\..\npython test_engine.py Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocati on. ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at Python.Runtime.Runtime.PyImport_ImportModule(String name) at Python.Runtime.PythonEngine.ImportModule(String name) in c:\Automation\PythonNet\src\runtime\pythonengine.cs:line 276 --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters , CultureInfo culture) at Python.Runtime.MethodBinder.Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, MethodInfo[] methodinfo) in c:\Automation\PythonNet\src\runtime\methodbinder.cs:line 356 at Python.Runtime.MethodObject.Invoke(IntPtr target, IntPtr args, IntPtr kw, MethodBase info) in c:\Automation\Python Net\src\runtime\methodobject.cs:line 63 at Python.Runtime.MethodBinding.tp_call(IntPtr ob, IntPtr args, IntPtr kw) in c:\Automation\PythonNet\src\runtime\met hodbinding.cs:line 135 at Python.Runtime.Runtime.Py_Main(Int32 argc, String[] argv) at Python.Runtime.PythonConsole.Main(String[] args) in c:\Automation\PythonNet\src\console\pythonconsole.cs:line 24 C:\Automation\PythonNet\src\tests> -------------- next part -------------- An HTML attachment was scrubbed... URL: From swpark71 at gmail.com Thu Apr 4 19:49:08 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Thu, 4 Apr 2013 10:49:08 -0700 Subject: [Python.NET] I can't run test_engine.py with nPython.exe. Would you tell me why? In-Reply-To: References: Message-ID: Now I'm getting different error message after I have nPython.exe which I compiled from source code. According to the comments from test_module.py, Line 209 # This should fail until System.Windows.Forms has been # imported or that assembly has been explicitly loaded. # True for Windows; Not so for Mono 2.8.1 Line 214 # The test fails when the project is compiled with MS VS 2005. Dunno why :( # Fails (as expected) on Late Binding model. Works as expected on an interactive sesson. Is this failure as we expected in windows machine? Thanks, Spark. C:\Automation\PythonNet\src\tests>..\..\npython test_module.py ........F................ ====================================================================== FAIL: testImplicitAssemblyLoad (__main__.ModuleTests) Test implicit assembly loading via import. ---------------------------------------------------------------------- Traceback (most recent call last): File "test_module.py", line 216, in testImplicitAssemblyLoad self.assertRaises(ImportError, test) AssertionError: ImportError not raised ---------------------------------------------------------------------- Ran 25 tests in 1.445s FAILED (failures=1) On Thu, Apr 4, 2013 at 8:34 AM, Seungweon Park wrote: > Hi, > > I ran every tests from src\tests. However, I can't run runtests.py and > test_module.py. > > test_module.py has an error message in console window and pops up "Python > Console" with "Python Console has stopped working" message. Would you tell > me what I need to check to run this script? It looks to me having a problem > when loading a module. > > Thanks, > Spark. > > C:\Automation\PythonNet\src\tests>..\..\npython test_engine.py > > Unhandled Exception: System.Reflection.TargetInvocationException: > Exception has been thrown by the target of an invocati > on. ---> System.AccessViolationException: Attempted to read or write > protected memory. This is often an indication that > other memory is corrupt. > at Python.Runtime.Runtime.PyImport_ImportModule(String name) > at Python.Runtime.PythonEngine.ImportModule(String name) in > c:\Automation\PythonNet\src\runtime\pythonengine.cs:line > 276 > --- End of inner exception stack trace --- > at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] > arguments, Signature sig, Boolean constructor) > at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, > Object[] parameters, Object[] arguments) > at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags > invokeAttr, Binder binder, Object[] parameters > , CultureInfo culture) > at Python.Runtime.MethodBinder.Invoke(IntPtr inst, IntPtr args, IntPtr > kw, MethodBase info, MethodInfo[] methodinfo) > in c:\Automation\PythonNet\src\runtime\methodbinder.cs:line 356 > at Python.Runtime.MethodObject.Invoke(IntPtr target, IntPtr args, > IntPtr kw, MethodBase info) in c:\Automation\Python > Net\src\runtime\methodobject.cs:line 63 > at Python.Runtime.MethodBinding.tp_call(IntPtr ob, IntPtr args, IntPtr > kw) in c:\Automation\PythonNet\src\runtime\met > hodbinding.cs:line 135 > at Python.Runtime.Runtime.Py_Main(Int32 argc, String[] argv) > at Python.Runtime.PythonConsole.Main(String[] args) in > c:\Automation\PythonNet\src\console\pythonconsole.cs:line 24 > > C:\Automation\PythonNet\src\tests> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From swpark71 at gmail.com Thu Apr 4 22:37:25 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Thu, 4 Apr 2013 13:37:25 -0700 Subject: [Python.NET] How to turn on console window from Windows System while debugging Embedded PythonNet app? Message-ID: Hi, Actually, my questions are 1. How to turn on console window(live) from Windows System while debugging Embedded PythonNet app? 2. How to capture python script execution output from C# code? I've been talking to Brad at fie.us about my issue which I can't get the output result of any python command using PythonEngine.RunString() or PythonEngine.RunSimpleString(). I've been tried to debug simple code with Python.Runtime project, but can't find how to turn on this console window, nor capture the python script execution output. What I'm trying to do is that I don't want to modify any python script when running a python script from C# code, so I have below code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Python.Runtime; using System.Diagnostics; namespace npythontest { public class Program { static void Main(string[] args) { PyObject po; PythonEngine.Initialize(); IntPtr pythonLock = PythonEngine.AcquireLock(); po = PythonEngine.RunString("execfile('c:\\cvs\\brocade.py')"); PythonEngine.ReleaseLock(pythonLock); PythonEngine.Shutdown(); } } } and a.py prints out many string output. I want to capture this output by RunString()/RunSimpleString() method, but it doesn't return any result except 'null'. It seems it isn't for getting output. Then, while talking to Brad, his screenshot from his Mac OS with Mono displays the execution result output on an window like below, so wonder if windows environment can have same console window. Previously, Oleksii and Sharon mentioned in the thread http://mail.python.org/pipermail/pythondotnet/2011-March/001103.html, but don't know it's already implemented or not. However, I can't find how to have same environment from my window system like Brad's Mac has. So would you help me how to capture the python script output or have console window for debugging when I'm using embedded PythonNet? Thank you, Spark. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Screen Shot 2013-04-01 at 6.22.50 PM.png Type: image/png Size: 131895 bytes Desc: not available URL: From swpark71 at gmail.com Thu Apr 4 22:40:05 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Thu, 4 Apr 2013 13:40:05 -0700 Subject: [Python.NET] How to turn on console window from Windows System while debugging Embedded PythonNet app? In-Reply-To: References: Message-ID: Image file is not attached. Here it goes. On Thu, Apr 4, 2013 at 1:37 PM, Seungweon Park wrote: > Hi, > > Actually, my questions are > > 1. How to turn on console window(live) from Windows System > while debugging Embedded PythonNet app? > 2. How to capture python script execution output from C# code? > > I've been talking to Brad at fie.us about my issue which I can't get the > output result of any python command using PythonEngine.RunString() or > PythonEngine.RunSimpleString(). > I've been tried to debug simple code with Python.Runtime project, but > can't find how to turn on this console window, nor capture the python > script execution output. > > What I'm trying to do is that I don't want to modify any python script > when running a python script from C# code, so I have below code: > > > using System; > using System.Collections.Generic; > using System.Linq; > using System.Text; > using System.Threading.Tasks; > using Python.Runtime; > using System.Diagnostics; > > namespace npythontest > { > public class Program > { > static void Main(string[] args) > { > PyObject po; > > PythonEngine.Initialize(); > > IntPtr pythonLock = PythonEngine.AcquireLock(); > po = PythonEngine.RunString("execfile('c:\\cvs\\brocade.py')"); > PythonEngine.ReleaseLock(pythonLock); > > PythonEngine.Shutdown(); > } > } > } > > and a.py prints out many string output. I want to capture this output by > RunString()/RunSimpleString() method, but it doesn't return any result > except 'null'. It seems it isn't for getting output. > > Then, while talking to Brad, his screenshot from his Mac OS with Mono > displays the execution result output on an window like below, so wonder if > windows environment can have same console window. > Previously, Oleksii and Sharon mentioned in the thread > http://mail.python.org/pipermail/pythondotnet/2011-March/001103.html, but > don't know it's already implemented or not. However, I can't find how to > have same environment from my window system like Brad's Mac has. > > So would you help me how to capture the python script output or have > console window for debugging when I'm using embedded PythonNet? > > Thank you, > Spark. > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Screen Shot 2013-04-01 at 6.22.50 PM.png Type: image/png Size: 131895 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: mono_screenshot_pythonnet.png Type: image/png Size: 131895 bytes Desc: not available URL: From brad at fie.us Thu Apr 4 22:51:28 2013 From: brad at fie.us (brad at fie.us) Date: Thu, 4 Apr 2013 16:51:28 -0400 Subject: [Python.NET] How to turn on console window from Windows System while debugging Embedded PythonNet app? In-Reply-To: References: Message-ID: <8A51847C-40AE-40C0-8E8C-D62C9C08C29B@fie.us> What happens when you run a compiled application like mine, that has both c# and python console output, directly from within the windows command line cmd.exe? Do you see the WriteLine() results from C# but not PythonNet? That will tell you if it's an execution environment issue or an actual programming issue. Which is still in question I think. -brad On Apr 4, 2013, at 4:40 PM, Seungweon Park wrote: > Image file is not attached. Here it goes. > > > On Thu, Apr 4, 2013 at 1:37 PM, Seungweon Park wrote: > Hi, > > Actually, my questions are > > 1. How to turn on console window(live) from Windows System while debugging Embedded PythonNet app? > 2. How to capture python script execution output from C# code? > > I've been talking to Brad at fie.us about my issue which I can't get the output result of any python command using PythonEngine.RunString() or PythonEngine.RunSimpleString(). > I've been tried to debug simple code with Python.Runtime project, but can't find how to turn on this console window, nor capture the python script execution output. > > What I'm trying to do is that I don't want to modify any python script when running a python script from C# code, so I have below code: > > > using System; > using System.Collections.Generic; > using System.Linq; > using System.Text; > using System.Threading.Tasks; > using Python.Runtime; > using System.Diagnostics; > > namespace npythontest > { > public class Program > { > static void Main(string[] args) > { > PyObject po; > > PythonEngine.Initialize(); > > IntPtr pythonLock = PythonEngine.AcquireLock(); > po = PythonEngine.RunString("execfile('c:\\cvs\\brocade.py')"); > PythonEngine.ReleaseLock(pythonLock); > > PythonEngine.Shutdown(); > } > } > } > > and a.py prints out many string output. I want to capture this output by RunString()/RunSimpleString() method, but it doesn't return any result except 'null'. It seems it isn't for getting output. > > Then, while talking to Brad, his screenshot from his Mac OS with Mono displays the execution result output on an window like below, so wonder if windows environment can have same console window. > Previously, Oleksii and Sharon mentioned in the thread http://mail.python.org/pipermail/pythondotnet/2011-March/001103.html, but don't know it's already implemented or not. However, I can't find how to have same environment from my window system like Brad's Mac has. > > So would you help me how to capture the python script output or have console window for debugging when I'm using embedded PythonNet? > > Thank you, > Spark. > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Fri Apr 5 03:38:34 2013 From: brad at fie.us (brad at fie.us) Date: Thu, 4 Apr 2013 21:38:34 -0400 Subject: [Python.NET] How to turn on console window from Windows System while debugging Embedded PythonNet app? In-Reply-To: References: <8A51847C-40AE-40C0-8E8C-D62C9C08C29B@fie.us> Message-ID: <2FC4BDC7-5F87-49AA-88B1-D53D9DC28885@fie.us> It's an escape character issue. Since you are pasting source code in your source code, you need to double escape. Probably as follows: PythonEngine.RunSimpleString("execfile('c:\\\\temp\\\\a.py')"); the c# parser turns that into: execfile('c:\\temp\\a.py') And then python runs those escape characters and gets: c:\temp\a.py If you don't double escape, C# sends: execfile('c:\temp\a.py') And therefore the escape characters \t and \a are executed, resulting in that weird value you got. On Apr 4, 2013, at 5:45 PM, Seungweon Park wrote: > I retested with same code as you have and added online to execute a.py. It looks it running but not the last line > > po = PythonEngine.RunString("execfile('c:\\temp\\a.py')"); > > > > > > > So I changed to > > PythonEngine.RunSimpleString("execfile('c:\\temp\\a.py')"); > > then, I got > > > > Hello World! > > my\path > other\path > 5 > Traceback (most recent call last): > File "", line 1, in > IOError: [Errno 2] No such file or directory: 'c:\temp\x07.py' > > I don't know why it converted to 'c:\temp\x07.py' from 'c:\temp\a.py', and got the error. Any idea? > > > > > On Thu, Apr 4, 2013 at 2:25 PM, Seungweon Park wrote: > As you see the screenshot, I ran same application like you, but it doesn't have any output which a.py's supposed to print 'aa' in the screen after "Hello World!". > > > > > > On Thu, Apr 4, 2013 at 1:51 PM, brad at fie.us wrote: > What happens when you run a compiled application like mine, that has both c# and python console output, directly from within the windows command line cmd.exe? Do you see the WriteLine() results from C# but not PythonNet? > > That will tell you if it's an execution environment issue or an actual programming issue. Which is still in question I think. > > -brad > > On Apr 4, 2013, at 4:40 PM, Seungweon Park wrote: > >> Image file is not attached. Here it goes. >> >> >> On Thu, Apr 4, 2013 at 1:37 PM, Seungweon Park wrote: >> Hi, >> >> Actually, my questions are >> >> 1. How to turn on console window(live) from Windows System while debugging Embedded PythonNet app? >> 2. How to capture python script execution output from C# code? >> >> I've been talking to Brad at fie.us about my issue which I can't get the output result of any python command using PythonEngine.RunString() or PythonEngine.RunSimpleString(). >> I've been tried to debug simple code with Python.Runtime project, but can't find how to turn on this console window, nor capture the python script execution output. >> >> What I'm trying to do is that I don't want to modify any python script when running a python script from C# code, so I have below code: >> >> >> using System; >> using System.Collections.Generic; >> using System.Linq; >> using System.Text; >> using System.Threading.Tasks; >> using Python.Runtime; >> using System.Diagnostics; >> >> namespace npythontest >> { >> public class Program >> { >> static void Main(string[] args) >> { >> PyObject po; >> >> PythonEngine.Initialize(); >> >> IntPtr pythonLock = PythonEngine.AcquireLock(); >> po = PythonEngine.RunString("execfile('c:\\cvs\\brocade.py')"); >> PythonEngine.ReleaseLock(pythonLock); >> >> PythonEngine.Shutdown(); >> } >> } >> } >> >> and a.py prints out many string output. I want to capture this output by RunString()/RunSimpleString() method, but it doesn't return any result except 'null'. It seems it isn't for getting output. >> >> Then, while talking to Brad, his screenshot from his Mac OS with Mono displays the execution result output on an window like below, so wonder if windows environment can have same console window. >> Previously, Oleksii and Sharon mentioned in the thread http://mail.python.org/pipermail/pythondotnet/2011-March/001103.html, but don't know it's already implemented or not. However, I can't find how to have same environment from my window system like Brad's Mac has. >> >> So would you help me how to capture the python script output or have console window for debugging when I'm using embedded PythonNet? >> >> Thank you, >> Spark. >> >> >> >> >> > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From swpark71 at gmail.com Thu Apr 4 23:25:39 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Thu, 4 Apr 2013 14:25:39 -0700 Subject: [Python.NET] How to turn on console window from Windows System while debugging Embedded PythonNet app? In-Reply-To: <8A51847C-40AE-40C0-8E8C-D62C9C08C29B@fie.us> References: <8A51847C-40AE-40C0-8E8C-D62C9C08C29B@fie.us> Message-ID: As you see the screenshot, I ran same application like you, but it doesn't have any output which a.py's supposed to print 'aa' in the screen after "Hello World!". [image: Inline image 2] On Thu, Apr 4, 2013 at 1:51 PM, brad at fie.us wrote: > What happens when you run a compiled application like mine, that has both > c# and python console output, directly from within the windows command line > cmd.exe? Do you see the WriteLine() results from C# but not PythonNet? > > That will tell you if it's an execution environment issue or an actual > programming issue. Which is still in question I think. > > -brad > > On Apr 4, 2013, at 4:40 PM, Seungweon Park wrote: > > Image file is not attached. Here it goes. > > > On Thu, Apr 4, 2013 at 1:37 PM, Seungweon Park wrote: > >> Hi, >> >> Actually, my questions are >> >> 1. How to turn on console window(live) from Windows System >> while debugging Embedded PythonNet app? >> 2. How to capture python script execution output from C# code? >> >> I've been talking to Brad at fie.us about my issue which I can't get the >> output result of any python command using PythonEngine.RunString() or >> PythonEngine.RunSimpleString(). >> I've been tried to debug simple code with Python.Runtime project, but >> can't find how to turn on this console window, nor capture the python >> script execution output. >> >> What I'm trying to do is that I don't want to modify any python script >> when running a python script from C# code, so I have below code: >> >> >> using System; >> using System.Collections.Generic; >> using System.Linq; >> using System.Text; >> using System.Threading.Tasks; >> using Python.Runtime; >> using System.Diagnostics; >> >> namespace npythontest >> { >> public class Program >> { >> static void Main(string[] args) >> { >> PyObject po; >> >> PythonEngine.Initialize(); >> >> IntPtr pythonLock = PythonEngine.AcquireLock(); >> po = PythonEngine.RunString("execfile('c:\\cvs\\brocade.py')"); >> PythonEngine.ReleaseLock(pythonLock); >> >> PythonEngine.Shutdown(); >> } >> } >> } >> >> and a.py prints out many string output. I want to capture this output by >> RunString()/RunSimpleString() method, but it doesn't return any result >> except 'null'. It seems it isn't for getting output. >> >> Then, while talking to Brad, his screenshot from his Mac OS with Mono >> displays the execution result output on an window like below, so wonder if >> windows environment can have same console window. >> Previously, Oleksii and Sharon mentioned in the thread >> http://mail.python.org/pipermail/pythondotnet/2011-March/001103.html, >> but don't know it's already implemented or not. However, I can't find how >> to have same environment from my window system like Brad's Mac has. >> >> So would you help me how to capture the python script output or have >> console window for debugging when I'm using embedded PythonNet? >> >> Thank you, >> Spark. >> >> >> >> > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 58574 bytes Desc: not available URL: From swpark71 at gmail.com Thu Apr 4 23:45:44 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Thu, 4 Apr 2013 14:45:44 -0700 Subject: [Python.NET] How to turn on console window from Windows System while debugging Embedded PythonNet app? In-Reply-To: References: <8A51847C-40AE-40C0-8E8C-D62C9C08C29B@fie.us> Message-ID: I retested with same code as you have and added online to execute a.py. It looks it running but not the last line po = PythonEngine.RunString("execfile('c:\\temp\\a.py')"); [image: Inline image 2] So I changed to PythonEngine.RunSimpleString("execfile('c:\\temp\\a.py')"); then, I got [image: Inline image 3] Hello World! my\path other\path 5 Traceback (most recent call last): File "", line 1, in IOError: [Errno 2] No such file or directory: 'c:\temp\x07.py' I don't know why it converted to 'c:\temp\x07.py' from 'c:\temp\a.py', and got the error. Any idea? On Thu, Apr 4, 2013 at 2:25 PM, Seungweon Park wrote: > As you see the screenshot, I ran same application like you, but it doesn't > have any output which a.py's supposed to print 'aa' in the screen after > "Hello World!". > > > [image: Inline image 2] > > > On Thu, Apr 4, 2013 at 1:51 PM, brad at fie.us wrote: > >> What happens when you run a compiled application like mine, that has both >> c# and python console output, directly from within the windows command line >> cmd.exe? Do you see the WriteLine() results from C# but not PythonNet? >> >> That will tell you if it's an execution environment issue or an actual >> programming issue. Which is still in question I think. >> >> -brad >> >> On Apr 4, 2013, at 4:40 PM, Seungweon Park wrote: >> >> Image file is not attached. Here it goes. >> >> >> On Thu, Apr 4, 2013 at 1:37 PM, Seungweon Park wrote: >> >>> Hi, >>> >>> Actually, my questions are >>> >>> 1. How to turn on console window(live) from Windows System >>> while debugging Embedded PythonNet app? >>> 2. How to capture python script execution output from C# >>> code? >>> >>> I've been talking to Brad at fie.us about my issue which I can't get the >>> output result of any python command using PythonEngine.RunString() or >>> PythonEngine.RunSimpleString(). >>> I've been tried to debug simple code with Python.Runtime project, but >>> can't find how to turn on this console window, nor capture the python >>> script execution output. >>> >>> What I'm trying to do is that I don't want to modify any python script >>> when running a python script from C# code, so I have below code: >>> >>> >>> using System; >>> using System.Collections.Generic; >>> using System.Linq; >>> using System.Text; >>> using System.Threading.Tasks; >>> using Python.Runtime; >>> using System.Diagnostics; >>> >>> namespace npythontest >>> { >>> public class Program >>> { >>> static void Main(string[] args) >>> { >>> PyObject po; >>> >>> PythonEngine.Initialize(); >>> >>> IntPtr pythonLock = PythonEngine.AcquireLock(); >>> po = PythonEngine.RunString("execfile('c:\\cvs\\brocade.py')"); >>> PythonEngine.ReleaseLock(pythonLock); >>> >>> PythonEngine.Shutdown(); >>> } >>> } >>> } >>> >>> and a.py prints out many string output. I want to capture this output >>> by RunString()/RunSimpleString() method, but it doesn't return any result >>> except 'null'. It seems it isn't for getting output. >>> >>> Then, while talking to Brad, his screenshot from his Mac OS with Mono >>> displays the execution result output on an window like below, so wonder if >>> windows environment can have same console window. >>> Previously, Oleksii and Sharon mentioned in the thread >>> http://mail.python.org/pipermail/pythondotnet/2011-March/001103.html, >>> but don't know it's already implemented or not. However, I can't find how >>> to have same environment from my window system like Brad's Mac has. >>> >>> So would you help me how to capture the python script output or have >>> console window for debugging when I'm using embedded PythonNet? >>> >>> Thank you, >>> Spark. >>> >>> >>> >>> >> >> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 85490 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 82798 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 58574 bytes Desc: not available URL: From swpark71 at gmail.com Fri Apr 5 18:48:39 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Fri, 5 Apr 2013 09:48:39 -0700 Subject: [Python.NET] How to turn on console window from Windows System while debugging Embedded PythonNet app? In-Reply-To: <2FC4BDC7-5F87-49AA-88B1-D53D9DC28885@fie.us> References: <8A51847C-40AE-40C0-8E8C-D62C9C08C29B@fie.us> <2FC4BDC7-5F87-49AA-88B1-D53D9DC28885@fie.us> Message-ID: WOW. Now I got it. Thank you much for the kind explanation. Now it works as charm in Console Application in Windows system. In the meantime, if it is not console window application, how I can see/capture the text output? (I know it will work but want to capture the output) Any idea? On Thu, Apr 4, 2013 at 6:38 PM, brad at fie.us wrote: > It's an escape character issue. > > Since you are pasting source code in your source code, you need to double > escape. Probably as follows: > > PythonEngine.RunSimpleString("execfile('c:\\\\temp\\\\a.py')"); > > the c# parser turns that into: execfile('c:\\temp\\a.py') > > And then python runs those escape characters and gets: c:\temp\a.py > > If you don't double escape, C# sends: execfile('c:\temp\a.py') > > And therefore the escape characters \t and \a are executed, resulting in > that weird value you got. > > > On Apr 4, 2013, at 5:45 PM, Seungweon Park wrote: > > I retested with same code as you have and added online to execute a.py. It > looks it running but not the last line > > po = PythonEngine.RunString("execfile('c:\\temp\\a.py')"); > > > > > > > So I changed to > > PythonEngine.RunSimpleString("execfile('c:\\temp\\a.py')"); > > then, I got > > > > Hello World! > > my\path > other\path > 5 > Traceback (most recent call last): > File "", line 1, in > IOError: [Errno 2] No such file or directory: 'c:\temp\x07.py' > > I don't know why it converted to 'c:\temp\x07.py' from 'c:\temp\a.py', and > got the error. Any idea? > > > > > On Thu, Apr 4, 2013 at 2:25 PM, Seungweon Park wrote: > >> As you see the screenshot, I ran same application like you, but it >> doesn't have any output which a.py's supposed to print 'aa' in the screen >> after "Hello World!". >> >> >> >> >> >> On Thu, Apr 4, 2013 at 1:51 PM, brad at fie.us wrote: >> >>> What happens when you run a compiled application like mine, that has >>> both c# and python console output, directly from within the windows command >>> line cmd.exe? Do you see the WriteLine() results from C# but not PythonNet? >>> >>> That will tell you if it's an execution environment issue or an actual >>> programming issue. Which is still in question I think. >>> >>> -brad >>> >>> On Apr 4, 2013, at 4:40 PM, Seungweon Park wrote: >>> >>> Image file is not attached. Here it goes. >>> >>> >>> On Thu, Apr 4, 2013 at 1:37 PM, Seungweon Park wrote: >>> >>>> Hi, >>>> >>>> Actually, my questions are >>>> >>>> 1. How to turn on console window(live) from Windows System >>>> while debugging Embedded PythonNet app? >>>> 2. How to capture python script execution output from C# >>>> code? >>>> >>>> I've been talking to Brad at fie.us about my issue which I can't get the >>>> output result of any python command using PythonEngine.RunString() or >>>> PythonEngine.RunSimpleString(). >>>> I've been tried to debug simple code with Python.Runtime project, but >>>> can't find how to turn on this console window, nor capture the python >>>> script execution output. >>>> >>>> What I'm trying to do is that I don't want to modify any python script >>>> when running a python script from C# code, so I have below code: >>>> >>>> >>>> using System; >>>> using System.Collections.Generic; >>>> using System.Linq; >>>> using System.Text; >>>> using System.Threading.Tasks; >>>> using Python.Runtime; >>>> using System.Diagnostics; >>>> >>>> namespace npythontest >>>> { >>>> public class Program >>>> { >>>> static void Main(string[] args) >>>> { >>>> PyObject po; >>>> >>>> PythonEngine.Initialize(); >>>> >>>> IntPtr pythonLock = PythonEngine.AcquireLock(); >>>> po = PythonEngine.RunString("execfile('c:\\cvs\\brocade.py')"); >>>> PythonEngine.ReleaseLock(pythonLock); >>>> >>>> PythonEngine.Shutdown(); >>>> } >>>> } >>>> } >>>> >>>> and a.py prints out many string output. I want to capture this output >>>> by RunString()/RunSimpleString() method, but it doesn't return any result >>>> except 'null'. It seems it isn't for getting output. >>>> >>>> Then, while talking to Brad, his screenshot from his Mac OS with Mono >>>> displays the execution result output on an window like below, so wonder if >>>> windows environment can have same console window. >>>> Previously, Oleksii and Sharon mentioned in the thread >>>> http://mail.python.org/pipermail/pythondotnet/2011-March/001103.html, >>>> but don't know it's already implemented or not. However, I can't find how >>>> to have same environment from my window system like Brad's Mac has. >>>> >>>> So would you help me how to capture the python script output or have >>>> console window for debugging when I'm using embedded PythonNet? >>>> >>>> Thank you, >>>> Spark. >>>> >>>> >>>> >>>> >>> >>> >>> >>> >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From swpark71 at gmail.com Fri Apr 5 19:39:04 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Fri, 5 Apr 2013 10:39:04 -0700 Subject: [Python.NET] How to show the Console window In-Reply-To: References: Message-ID: Hi Oleksii & Sharon, If you've done this before, would you share which I can get a console window in embedded Python.Net and get the Python string output from C#? Thank you, Spark. On Tue, Mar 1, 2011 at 1:33 PM, Oleksii Bidiuk wrote: > Hi Sharon, > > I haven't found a way to run a console, but I had achieved a similar > effect by redirecting the stdout and stderr from within Python (as > suggested some time ago by Guido himself in a related embedded CPython > post) to a .NET object and then show the incoming strings in a TextBlock (I > am using a WPF app that hosts Python.NET). Below is a very short > description of what I have done. Please let me know if this is indeed what > you were looking for (or perhaps somebody else), I will prepare a more > detailed post then (need to recap details from code). > > To achieve having 'live' console output I have used some 'setup script' > and 'clean up' scripts executed before and after the user-defined script. > In the setup script I first backup the curent value of sys.std* objects and > then assign my own (.NET) object to sys.stdout and in the clean up part I > restore the original std* values (similar to the sample for inserting > certain path to the sys.path discussed before). > > To make use of the technique described above you need to have a .NET > object that implements the same interface as python stream (meaning write, > writelines, etc methods, see dir(sys.stdout) for all the details). In my > experience write() and writelines() is enough. Having that you can pass an > instance of such object to your Python code. As soon as you have the > information coming through your .NET object methods you can do things like > raising events, adding text to GUI, dump to a file, etc. It does require a > bit of additional work, (which I honestly already expected to see already > in Python.NET) and to some extend similar to the concept of console > redirection per script context in IronPython, although in IronPython it is > done in a 'native' .NET way. > > I am not sure this is THE best solution and other suggestions are more > than welcome! > > > 2011/3/1 Sharon Rozenblum > >> Hi! >> >> >> >> Is there a way to show the console window when running Python from C# (in >> order to see the Python outputs, when the c# project is not console >> application) >> >> >> >> Thanks, >> >> >> >> SHARON >> >> >> >> >> > > -- > oleksii > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Fri Apr 5 19:40:09 2013 From: brad at fie.us (brad at fie.us) Date: Fri, 5 Apr 2013 13:40:09 -0400 Subject: [Python.NET] How to turn on console window from Windows System while debugging Embedded PythonNet app? In-Reply-To: References: <8A51847C-40AE-40C0-8E8C-D62C9C08C29B@fie.us> <2FC4BDC7-5F87-49AA-88B1-D53D9DC28885@fie.us> Message-ID: Since all you are telling it to do is run a script and you are looking to capture it's output, I'd just use System.Diagnostics.Process to run "python.exe" with the args "c:\\temp\\a.py". Then I'd use the returned Process object's Output stream object to read the lines from it's standard output and standard error. No PythonNet required. The other way to do it if you insist on using PythonNet to embed python rather than just spawn it as a subprocess, you can redirect use Console to redirect the streams for the running process yourself. That should probably work as well. On Apr 5, 2013, at 12:48 PM, Seungweon Park wrote: > WOW. Now I got it. Thank you much for the kind explanation. Now it works as charm in Console Application in Windows system. > In the meantime, if it is not console window application, how I can see/capture the text output? (I know it will work but want to capture the output) > > Any idea? > > > On Thu, Apr 4, 2013 at 6:38 PM, brad at fie.us wrote: > It's an escape character issue. > > Since you are pasting source code in your source code, you need to double escape. Probably as follows: > > PythonEngine.RunSimpleString("execfile('c:\\\\temp\\\\a.py')"); > > the c# parser turns that into: execfile('c:\\temp\\a.py') > > And then python runs those escape characters and gets: c:\temp\a.py > > If you don't double escape, C# sends: execfile('c:\temp\a.py') > > And therefore the escape characters \t and \a are executed, resulting in that weird value you got. > > > On Apr 4, 2013, at 5:45 PM, Seungweon Park wrote: > >> I retested with same code as you have and added online to execute a.py. It looks it running but not the last line >> >> po = PythonEngine.RunString("execfile('c:\\temp\\a.py')"); >> >> >> >> >> >> >> So I changed to >> >> PythonEngine.RunSimpleString("execfile('c:\\temp\\a.py')"); >> >> then, I got >> >> >> >> Hello World! >> >> my\path >> other\path >> 5 >> Traceback (most recent call last): >> File "", line 1, in >> IOError: [Errno 2] No such file or directory: 'c:\temp\x07.py' >> >> I don't know why it converted to 'c:\temp\x07.py' from 'c:\temp\a.py', and got the error. Any idea? >> >> >> >> >> On Thu, Apr 4, 2013 at 2:25 PM, Seungweon Park wrote: >> As you see the screenshot, I ran same application like you, but it doesn't have any output which a.py's supposed to print 'aa' in the screen after "Hello World!". >> >> >> >> >> >> On Thu, Apr 4, 2013 at 1:51 PM, brad at fie.us wrote: >> What happens when you run a compiled application like mine, that has both c# and python console output, directly from within the windows command line cmd.exe? Do you see the WriteLine() results from C# but not PythonNet? >> >> That will tell you if it's an execution environment issue or an actual programming issue. Which is still in question I think. >> >> -brad >> >> On Apr 4, 2013, at 4:40 PM, Seungweon Park wrote: >> >>> Image file is not attached. Here it goes. >>> >>> >>> On Thu, Apr 4, 2013 at 1:37 PM, Seungweon Park wrote: >>> Hi, >>> >>> Actually, my questions are >>> >>> 1. How to turn on console window(live) from Windows System while debugging Embedded PythonNet app? >>> 2. How to capture python script execution output from C# code? >>> >>> I've been talking to Brad at fie.us about my issue which I can't get the output result of any python command using PythonEngine.RunString() or PythonEngine.RunSimpleString(). >>> I've been tried to debug simple code with Python.Runtime project, but can't find how to turn on this console window, nor capture the python script execution output. >>> >>> What I'm trying to do is that I don't want to modify any python script when running a python script from C# code, so I have below code: >>> >>> >>> using System; >>> using System.Collections.Generic; >>> using System.Linq; >>> using System.Text; >>> using System.Threading.Tasks; >>> using Python.Runtime; >>> using System.Diagnostics; >>> >>> namespace npythontest >>> { >>> public class Program >>> { >>> static void Main(string[] args) >>> { >>> PyObject po; >>> >>> PythonEngine.Initialize(); >>> >>> IntPtr pythonLock = PythonEngine.AcquireLock(); >>> po = PythonEngine.RunString("execfile('c:\\cvs\\brocade.py')"); >>> PythonEngine.ReleaseLock(pythonLock); >>> >>> PythonEngine.Shutdown(); >>> } >>> } >>> } >>> >>> and a.py prints out many string output. I want to capture this output by RunString()/RunSimpleString() method, but it doesn't return any result except 'null'. It seems it isn't for getting output. >>> >>> Then, while talking to Brad, his screenshot from his Mac OS with Mono displays the execution result output on an window like below, so wonder if windows environment can have same console window. >>> Previously, Oleksii and Sharon mentioned in the thread http://mail.python.org/pipermail/pythondotnet/2011-March/001103.html, but don't know it's already implemented or not. However, I can't find how to have same environment from my window system like Brad's Mac has. >>> >>> So would you help me how to capture the python script output or have console window for debugging when I'm using embedded PythonNet? >>> >>> Thank you, >>> Spark. >>> >>> >>> >>> >>> >> >> >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From msutton at ucsd.edu Mon Apr 8 07:46:37 2013 From: msutton at ucsd.edu (msutton) Date: Sun, 07 Apr 2013 22:46:37 -0700 Subject: [Python.NET] import clr causes windows service script to fail Message-ID: <516259BD.80705@ucsd.edu> Import clr causes windows service script to fail. Windows Service script is for Pyramid: https://github.com/Pylons/pyramid_cookbook/blob/master/deployment/windows.rst Without WS script, "import clr" from python works. Without "import clr", WS script works. Together they fail. Setting "import clr" in script, the Windows Service will install but won't start. Setting "import clr" in any of the Pyramid views and the Pyramid application fails when the view is called. From barton at bcdesignswell.com Mon Apr 8 07:56:12 2013 From: barton at bcdesignswell.com (Barton) Date: Sun, 07 Apr 2013 22:56:12 -0700 Subject: [Python.NET] import clr causes windows service script to fail In-Reply-To: <516259BD.80705@ucsd.edu> References: <516259BD.80705@ucsd.edu> Message-ID: <51625BFC.9060104@bcdesignswell.com> That's usually x86 vs. x64 incompatibility - we need more info from you on this. Sometimes it's simply a path configuration problem when the caller can't find the DLLs required. On 04/07/2013 10:46 PM, msutton wrote: > Import clr causes windows service script to fail. > Windows Service script is for Pyramid: > https://github.com/Pylons/pyramid_cookbook/blob/master/deployment/windows.rst > > Without WS script, "import clr" from python works. > Without "import clr", WS script works. > Together they fail. Setting "import clr" in script, the Windows > Service will install but won't start. Setting "import clr" in any of > the Pyramid views and the Pyramid application fails when the view is > called. > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > From barton at bcdesignswell.com Mon Apr 8 08:08:46 2013 From: barton at bcdesignswell.com (Barton) Date: Sun, 07 Apr 2013 23:08:46 -0700 Subject: [Python.NET] How to Compile python for .Net in VS 2010 in .Net 4.0 In-Reply-To: <1528044003.1575910.1364221410802.JavaMail.root@wayne.edu> References: <1528044003.1575910.1364221410802.JavaMail.root@wayne.edu> Message-ID: <51625EEE.30309@bcdesignswell.com> That's usually the multi-byte character size symbol being set for Linux/Unix. For Windows you want UCS2 (two-byte characters) Seems some of my Linux settings may have leaked onto the repo. Since discovering that the post build event has not been needed since early .NET V2.0, I'm working on a unified build environment. Hopefully the repo will be updated in sort order. Thanks. On 03/25/2013 07:23 AM, Rama Nanditha Danda wrote: > Hello, > > I downloaded from SVN, and tried to compile it in VS2010.I have Python 2.6.6 version on 64 bit windows 7. > I changed projects framework t0 4.0 > I changed clrmodule.il version to 4:0:0:0 > changed post build events command line to %windir%\Microsoft.NET\Framework\v4.0.30319\ilasm /nologo /dll /quiet /output="$(TargetDir)clr.pyd" "$(ProjectDir)clrmodule.il" > I made above changes and rebuilded it.Python.exe is closing when i hit clr.AddReference > Could anyone , please guide me here. > Thank you, > Rama Danda > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > From msutton at ucsd.edu Mon Apr 8 08:38:38 2013 From: msutton at ucsd.edu (msutton) Date: Sun, 07 Apr 2013 23:38:38 -0700 Subject: [Python.NET] import clr causes windows service script to fail In-Reply-To: <51625BFC.9060104@bcdesignswell.com> References: <516259BD.80705@ucsd.edu> <51625BFC.9060104@bcdesignswell.com> Message-ID: <516265EE.10100@ucsd.edu> Barton, You were right about the not finding the DLLs. I placed the clr.pyd and python.runtime.dll in the pywin32 egg directory and it seems to work now. Thanks! On 04/07/2013 10:56 PM, Barton wrote: > That's usually x86 vs. x64 incompatibility - we need more info from > you on this. > Sometimes it's simply a path configuration problem when the caller > can't find the DLLs required. > > On 04/07/2013 10:46 PM, msutton wrote: >> Import clr causes windows service script to fail. >> Windows Service script is for Pyramid: >> https://github.com/Pylons/pyramid_cookbook/blob/master/deployment/windows.rst >> >> Without WS script, "import clr" from python works. >> Without "import clr", WS script works. >> Together they fail. Setting "import clr" in script, the Windows >> Service will install but won't start. Setting "import clr" in any of >> the Pyramid views and the Pyramid application fails when the view is >> called. >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> http://mail.python.org/mailman/listinfo/pythondotnet >> > From barton at bcdesignswell.com Mon Apr 8 10:58:51 2013 From: barton at bcdesignswell.com (Barton) Date: Mon, 08 Apr 2013 01:58:51 -0700 Subject: [Python.NET] How to compile Python for .Net in VS2010 and .NET 4? In-Reply-To: References: Message-ID: <516286CB.7050606@bcdesignswell.com> An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/png Size: 44794 bytes Desc: not available URL: From barton at bcdesignswell.com Mon Apr 8 11:00:51 2013 From: barton at bcdesignswell.com (Barton) Date: Mon, 08 Apr 2013 02:00:51 -0700 Subject: [Python.NET] How to compile Python for .Net in VS2010 and .NET 4? In-Reply-To: <516286CB.7050606@bcdesignswell.com> References: <516286CB.7050606@bcdesignswell.com> Message-ID: <51628743.3040603@bcdesignswell.com> An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/png Size: 44794 bytes Desc: not available URL: From stephen.trudel at baml.com Thu Apr 18 00:06:45 2013 From: stephen.trudel at baml.com (Trudel, Stephen) Date: Wed, 17 Apr 2013 22:06:45 +0000 Subject: [Python.NET] Release Memory Message-ID: I have a simply Python script that creates a big DataTable, sets the reference None, and the does a GC. I cannot seem to reclaim managed memory. Any advice would be appreciated ---------------------------------------------------------------------- This message, and any attachments, is for the intended recipient(s) only, may contain information that is privileged, confidential and/or proprietary and subject to important terms and conditions available at http://www.bankofamerica.com/emaildisclaimer. If you are not the intended recipient, please delete this message. -------------- next part -------------- An HTML attachment was scrubbed... URL: From swpark71 at gmail.com Thu Apr 18 23:45:27 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Thu, 18 Apr 2013 14:45:27 -0700 Subject: [Python.NET] How to create an instance of C# from pythonnet? Message-ID: Hi, I have Adapter.dll with namespace 'AAA.BBB.Adapter" written in C# which gives network adapter information. I want to call one of method GetSpeed(). I don't know How to create an instance in python. Would you give me some clue for writing the same python code like below powershell script using python.net I don't see any sample code which python creates C# class instance. Python --------------------------- C:\CVS\Pythonnet>npython Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os,sys >>> sys.path.append("c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions") >>> sys.path ['', 'C:\\Python27\\lib\\site-packages\\paramiko-1.10.0-py2.7.egg', 'C:\\CVS\\Python\\libs', 'C:\\Windows\\system32\\pyt hon27.zip', 'C:\\Python27\\Lib', 'C:\\Python27\\DLLs', 'C:\\Python27\\Lib\\lib-tk', 'C:\\CVS\\Pythonnet', 'C:\\Python27' , 'C:\\Python27\\lib\\site-packages', 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\', 'c:\\cvs\\powershelliteexam ple\\networktestlibrary\\iteextensions'] >>> import clr >>> clr.FindAssembly("Adapter") u'c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions\\Adapter.dll' >>> clr.AddReference("Adapter") I don't know how to create an instance of Adapter. Thank you, Spark. Powershell ---------------------------- PS C:\CVS\PowershellITEExample> Import-Module .\LoadAdapter.psd1 PS C:\CVS\PowershellITEExample> $adapter = New-object -type "AAA.BBB.Adapter" PS C:\CVS\PowershellITEExample> $ret = $adapter.GetAdapter("TestAdapter", "oids.xml") PS C:\CVS\PowershellITEExample> $ret.Passed True PS C:\CVS\PowershellITEExample> $baseAdapter = $ret.FunctionReturnValue PS C:\CVS\PowershellITEExample> $baseAdapter.GetSpeed() Passed : True Failed : False Errored : False Status : Pass Description : Speed retrieved successfully. FunctionReturnValue : auto -------------- next part -------------- An HTML attachment was scrubbed... URL: From msutton at ucsd.edu Fri Apr 19 00:07:53 2013 From: msutton at ucsd.edu (msutton) Date: Thu, 18 Apr 2013 15:07:53 -0700 Subject: [Python.NET] How to create an instance of C# from pythonnet? In-Reply-To: References: Message-ID: <51706EB9.2000309@ucsd.edu> What I use is: import clr from System.Reflection import Assembly Assembly.LoadWithPartialName('Demo') from Render import Demo where the C# code has namespace Render and public class Demo. -Manuel On 04/18/2013 02:45 PM, Seungweon Park wrote: > Hi, > > I have Adapter.dll with namespace 'AAA.BBB.Adapter" written in C# > which gives network adapter information. > I want to call one of method GetSpeed(). I don't know How to create an > instance in python. > Would you give me some clue for writing the same python code like > below powershell script using python.net > I don't see any sample code which python creates C# class instance. > > > Python > --------------------------- > C:\CVS\Pythonnet>npython > Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import os,sys > >>> > sys.path.append("c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions") > >>> sys.path > ['', 'C:\\Python27\\lib\\site-packages\\paramiko-1.10.0-py2.7.egg', > 'C:\\CVS\\Python\\libs', 'C:\\Windows\\system32\\pyt > hon27.zip', 'C:\\Python27\\Lib', 'C:\\Python27\\DLLs', > 'C:\\Python27\\Lib\\lib-tk', 'C:\\CVS\\Pythonnet', 'C:\\Python27' > , 'C:\\Python27\\lib\\site-packages', > 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\', > 'c:\\cvs\\powershelliteexam > ple\\networktestlibrary\\iteextensions'] > >>> import clr > >>> clr.FindAssembly("Adapter") > u'c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions\\Adapter.dll' > >>> clr.AddReference("Adapter") > > > I don't know how to create an instance of Adapter. > > > Thank you, > Spark. > > > Powershell > ---------------------------- > PS C:\CVS\PowershellITEExample> Import-Module .\LoadAdapter.psd1 > PS C:\CVS\PowershellITEExample> $adapter = New-object -type > "AAA.BBB.Adapter" > PS C:\CVS\PowershellITEExample> $ret = > $adapter.GetAdapter("TestAdapter", "oids.xml") > PS C:\CVS\PowershellITEExample> $ret.Passed > True > PS C:\CVS\PowershellITEExample> $baseAdapter = $ret.FunctionReturnValue > PS C:\CVS\PowershellITEExample> $baseAdapter.GetSpeed() > > Passed : True > Failed : False > Errored : False > Status : Pass > Description : Speed retrieved successfully. > FunctionReturnValue : auto > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From swpark71 at gmail.com Fri Apr 19 00:42:46 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Thu, 18 Apr 2013 15:42:46 -0700 Subject: [Python.NET] How to create an instance of C# from pythonnet? In-Reply-To: <51706EB9.2000309@ucsd.edu> References: <51706EB9.2000309@ucsd.edu> Message-ID: Thank you for the reply. I did >>> import clr >>> from System.Reflection import Assembly >>> Assembly.LoadWithPartialName("Adapter") >>> from AAA.BBB import Adapter Traceback (most recent call last): File "", line 1, in ImportError: No module named AAA.BBB I don't know why I got this. :-( Any idea? On Thu, Apr 18, 2013 at 3:07 PM, msutton wrote: > What I use is: > > import clr > from System.Reflection import Assembly > Assembly.LoadWithPartialName('Demo') > from Render import Demo > > where the C# code has namespace Render and public class Demo. > > -Manuel > > > On 04/18/2013 02:45 PM, Seungweon Park wrote: > > Hi, > > I have Adapter.dll with namespace 'AAA.BBB.Adapter" written in C# which > gives network adapter information. > I want to call one of method GetSpeed(). I don't know How to create an > instance in python. > Would you give me some clue for writing the same python code like below > powershell script using python.net > I don't see any sample code which python creates C# class instance. > > > Python > --------------------------- > C:\CVS\Pythonnet>npython > Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] > on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import os,sys > >>> > sys.path.append("c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions") > >>> sys.path > ['', 'C:\\Python27\\lib\\site-packages\\paramiko-1.10.0-py2.7.egg', > 'C:\\CVS\\Python\\libs', 'C:\\Windows\\system32\\pyt > hon27.zip', 'C:\\Python27\\Lib', 'C:\\Python27\\DLLs', > 'C:\\Python27\\Lib\\lib-tk', 'C:\\CVS\\Pythonnet', 'C:\\Python27' > , 'C:\\Python27\\lib\\site-packages', > 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\', > 'c:\\cvs\\powershelliteexam > ple\\networktestlibrary\\iteextensions'] > >>> import clr > >>> clr.FindAssembly("Adapter") > > u'c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions\\Adapter.dll' > >>> clr.AddReference("Adapter") > > > I don't know how to create an instance of Adapter. > > > Thank you, > Spark. > > > Powershell > ---------------------------- > PS C:\CVS\PowershellITEExample> Import-Module .\LoadAdapter.psd1 > PS C:\CVS\PowershellITEExample> $adapter = New-object -type > "AAA.BBB.Adapter" > PS C:\CVS\PowershellITEExample> $ret = $adapter.GetAdapter("TestAdapter", > "oids.xml") > PS C:\CVS\PowershellITEExample> $ret.Passed > True > PS C:\CVS\PowershellITEExample> $baseAdapter = $ret.FunctionReturnValue > PS C:\CVS\PowershellITEExample> $baseAdapter.GetSpeed() > > Passed : True > Failed : False > Errored : False > Status : Pass > Description : Speed retrieved successfully. > FunctionReturnValue : auto > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.orghttp://mail.python.org/mailman/listinfo/pythondotnet > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From msutton at ucsd.edu Fri Apr 19 01:01:52 2013 From: msutton at ucsd.edu (msutton) Date: Thu, 18 Apr 2013 16:01:52 -0700 Subject: [Python.NET] How to create an instance of C# from pythonnet? In-Reply-To: References: <51706EB9.2000309@ucsd.edu> Message-ID: <51707B60.5030909@ucsd.edu> How about skip the import giving the error and call: clr.AAA.BBB.Adapter() I really don't know much about C#, or nested namespaces being called from python.net. You could try making a simpler C# dll and getting that to work and isolate the issue, which I think is the dot notated nested namespaces. -Manuel On 04/18/2013 03:42 PM, Seungweon Park wrote: > Thank you for the reply. > > I did > > >>> import clr > >>> from System.Reflection import Assembly > >>> Assembly.LoadWithPartialName("Adapter") > > >>> from AAA.BBB import Adapter > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named AAA.BBB > > I don't know why I got this. :-( > Any idea? > > > > On Thu, Apr 18, 2013 at 3:07 PM, msutton > wrote: > > What I use is: > > import clr > from System.Reflection import Assembly > Assembly.LoadWithPartialName('Demo') > from Render import Demo > > where the C# code has namespace Render and public class Demo. > > -Manuel > > > On 04/18/2013 02:45 PM, Seungweon Park wrote: >> Hi, >> >> I have Adapter.dll with namespace 'AAA.BBB.Adapter" written in C# >> which gives network adapter information. >> I want to call one of method GetSpeed(). I don't know How to >> create an instance in python. >> Would you give me some clue for writing the same python code like >> below powershell script using python.net >> I don't see any sample code which python creates C# class instance. >> >> >> Python >> --------------------------- >> C:\CVS\Pythonnet>npython >> Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit >> (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more >> information. >> >>> import os,sys >> >>> >> sys.path.append("c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions") >> >>> sys.path >> ['', >> 'C:\\Python27\\lib\\site-packages\\paramiko-1.10.0-py2.7.egg', >> 'C:\\CVS\\Python\\libs', 'C:\\Windows\\system32\\pyt >> hon27.zip', 'C:\\Python27\\Lib', 'C:\\Python27\\DLLs', >> 'C:\\Python27\\Lib\\lib-tk', 'C:\\CVS\\Pythonnet', 'C:\\Python27' >> , 'C:\\Python27\\lib\\site-packages', >> 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\', >> 'c:\\cvs\\powershelliteexam >> ple\\networktestlibrary\\iteextensions'] >> >>> import clr >> >>> clr.FindAssembly("Adapter") >> u'c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions\\Adapter.dll' >> >>> clr.AddReference("Adapter") >> >> >> I don't know how to create an instance of Adapter. >> >> >> Thank you, >> Spark. >> >> >> Powershell >> ---------------------------- >> PS C:\CVS\PowershellITEExample> Import-Module .\LoadAdapter.psd1 >> PS C:\CVS\PowershellITEExample> $adapter = New-object -type >> "AAA.BBB.Adapter" >> PS C:\CVS\PowershellITEExample> $ret = >> $adapter.GetAdapter("TestAdapter", "oids.xml") >> PS C:\CVS\PowershellITEExample> $ret.Passed >> True >> PS C:\CVS\PowershellITEExample> $baseAdapter = >> $ret.FunctionReturnValue >> PS C:\CVS\PowershellITEExample> $baseAdapter.GetSpeed() >> >> Passed : True >> Failed : False >> Errored : False >> Status : Pass >> Description : Speed retrieved successfully. >> FunctionReturnValue : auto >> >> >> _________________________________________________ >> Python.NET mailing list -PythonDotNet at python.org >> http://mail.python.org/mailman/listinfo/pythondotnet > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stephenp at otakuworld.com Fri Apr 19 06:14:44 2013 From: stephenp at otakuworld.com (Stephen P. Lepisto) Date: Thu, 18 Apr 2013 21:14:44 -0700 Subject: [Python.NET] How to create an instance of C# from pythonnet? In-Reply-To: References: <51706EB9.2000309@ucsd.edu> Message-ID: <5170C4B4.4030806@otakuworld.com> Try this from python with pythonNet installed (the current directory is assumed to contain Adapter.dll): import clr clr.AddReference("Adapter") # Load the Adapter.dll from AAA.BBB import Adapter # Get the Adapter class type adapter = Adapter() # Create instance of the Adapter class adapter.GetSpeed() # Call the method On 4/18/2013 3:42 PM, Seungweon Park wrote: > Thank you for the reply. > > I did > > >>> import clr > >>> from System.Reflection import Assembly > >>> Assembly.LoadWithPartialName("Adapter") > > >>> from AAA.BBB import Adapter > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named AAA.BBB > > I don't know why I got this. :-( > Any idea? > > > > On Thu, Apr 18, 2013 at 3:07 PM, msutton > wrote: > > What I use is: > > import clr > from System.Reflection import Assembly > Assembly.LoadWithPartialName('Demo') > from Render import Demo > > where the C# code has namespace Render and public class Demo. > > -Manuel > > > On 04/18/2013 02:45 PM, Seungweon Park wrote: >> Hi, >> >> I have Adapter.dll with namespace 'AAA.BBB.Adapter" written in C# >> which gives network adapter information. >> I want to call one of method GetSpeed(). I don't know How to >> create an instance in python. >> Would you give me some clue for writing the same python code like >> below powershell script using python.net >> I don't see any sample code which python creates C# class instance. >> >> >> Python >> --------------------------- >> C:\CVS\Pythonnet>npython >> Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit >> (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more >> information. >> >>> import os,sys >> >>> >> sys.path.append("c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions") >> >>> sys.path >> ['', >> 'C:\\Python27\\lib\\site-packages\\paramiko-1.10.0-py2.7.egg', >> 'C:\\CVS\\Python\\libs', 'C:\\Windows\\system32\\pyt >> hon27.zip', 'C:\\Python27\\Lib', 'C:\\Python27\\DLLs', >> 'C:\\Python27\\Lib\\lib-tk', 'C:\\CVS\\Pythonnet', 'C:\\Python27' >> , 'C:\\Python27\\lib\\site-packages', >> 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\', >> 'c:\\cvs\\powershelliteexam >> ple\\networktestlibrary\\iteextensions'] >> >>> import clr >> >>> clr.FindAssembly("Adapter") >> u'c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions\\Adapter.dll' >> >>> clr.AddReference("Adapter") >> >> >> I don't know how to create an instance of Adapter. >> >> >> Thank you, >> Spark. >> >> >> Powershell >> ---------------------------- >> PS C:\CVS\PowershellITEExample> Import-Module .\LoadAdapter.psd1 >> PS C:\CVS\PowershellITEExample> $adapter = New-object -type >> "AAA.BBB.Adapter" >> PS C:\CVS\PowershellITEExample> $ret = >> $adapter.GetAdapter("TestAdapter", "oids.xml") >> PS C:\CVS\PowershellITEExample> $ret.Passed >> True >> PS C:\CVS\PowershellITEExample> $baseAdapter = >> $ret.FunctionReturnValue >> PS C:\CVS\PowershellITEExample> $baseAdapter.GetSpeed() >> >> Passed : True >> Failed : False >> Errored : False >> Status : Pass >> Description : Speed retrieved successfully. >> FunctionReturnValue : auto >> >> >> _________________________________________________ >> Python.NET mailing list -PythonDotNet at python.org >> http://mail.python.org/mailman/listinfo/pythondotnet > > > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -- Stephen P. Lepisto -------------- next part -------------- An HTML attachment was scrubbed... URL: From swpark71 at gmail.com Fri Apr 19 19:45:34 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Fri, 19 Apr 2013 10:45:34 -0700 Subject: [Python.NET] How to create an instance of C# from pythonnet? In-Reply-To: <5170C4B4.4030806@otakuworld.com> References: <51706EB9.2000309@ucsd.edu> <5170C4B4.4030806@otakuworld.com> Message-ID: Thank you for the replies. Now, I recompiled Python.Net with .Net 4.0 and get below working with simple AAA.BBB.Adapter after reading http://stackoverflow.com/questions/14520888/clr-addreferenceexample-file-unable-to-find-assembly?rq=1 http://stackoverflow.com/questions/13259617/python-for-net-unable-to-find-assembly-error?rq=1 http://sourceforge.net/p/pythonnet/bugs/17/ http://sourceforge.net/p/pythonnet/bugs/18/ Now I have below sample code(Adapter.proj has two c# files), and experimented Class1.cs ----------- namespace AAA.BBB.CCC { public class Adapter { public string Function1() { return "AAA.BBB.CCC: Adapter Function1 Called"; } public void Function2() { Console.WriteLine("AAA.BBB.CCC: Adapter Function2"); } } public class Network { public string Function1() { return "AAA.BBB.CCC: Network Function1 called"; } public void Function2() { Console.WriteLine("AAA.BBB.CCC: Network Function2"); } } } namespace AAA.BBB { public class Adapter { public string Function1() { return "AAA.BBB: Adapter Function1 Called"; } public void Function2() { Console.WriteLine("AAA.BBB: Adapter Function2"); } } public class Network { public string Function1() { return "AAA.BBB: Network Function1 called"; } public void Function2() { Console.WriteLine("AAA.BBB: Network Function2"); } } } Class2.cs ----------- namespace AAA.CCC { public class Adapter { public string Function1() { return "AAA.CCC: Adapter Function1 Called"; } public void Function2() { Console.WriteLine("AAA.CCC: Adapter Function2"); } } } Then, I got below. It seems working great. C:\Automation\PythonNet>nPython.exe Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.append("c:\\automation\\pythonnet") >>> import clr >>> clr.FindAssembly("Adapter") u'Adapter.dll' >>> clr.AddReference("Adapter") >>> adapter1 = Adapter() Traceback (most recent call last): File "", line 1, in NameError: name 'Adapter' is not defined >>> from AAA.BBB.CCC import Adapter >>> from AAA.BBB.CCC import * >>> adapter1 = Adapter() >>> adapter1.Function1() u'AAA.BBB.CCC: Adapter Function1 Called' >>> adapter1.Function2() AAA.BBB.CCC: Adapter Function2 >>> network1 = Network() >>> network1.Function1() u'AAA.BBB.CCC: Network Function1 called' >>> from AAA.CCC import * >>> adapter1.Function1() u'AAA.BBB.CCC: Adapter Function1 Called' >>> adapter1 = Adapter() >>> adapter1.Function1() u'AAA.CCC: Adapter Function1 Called' >>> My questions are 1. I don't know how to specify different namespace of class when creating an instance. 2. The class that I already have has similar above layout in a project. Common project has many class files in it, and each class has different name space and class name. AddReference('Common') looks working and loaded, but can't import. >>> clr.AddReference('Common') >>> from Network import * Traceback (most recent call last): File "", line 1, in ImportError: No module named Network >>> from Network.Common import * Traceback (most recent call last): File "", line 1, in ImportError: No module named Network.Common >>> Difference is that Common project has [Serializable] and enabled "Make assembly COM-Visible" [Serializable] [Description("SimpleDictionary")] public class SimpleDictionary : ISimpleDictionary { ... } Any thoughts? Wonder if there is a way to list available class after AddReference(). Thanks, Spark. On Thu, Apr 18, 2013 at 9:14 PM, Stephen P. Lepisto wrote: > Try this from python with pythonNet installed (the current directory is > assumed to contain Adapter.dll): > > import clr > clr.AddReference("Adapter") # Load the Adapter.dll > from AAA.BBB import Adapter # Get the Adapter class type > adapter = Adapter() # Create instance of the Adapter class > adapter.GetSpeed() # Call the method > > > > On 4/18/2013 3:42 PM, Seungweon Park wrote: > > Thank you for the reply. > > I did > > >>> import clr > >>> from System.Reflection import Assembly > >>> Assembly.LoadWithPartialName("Adapter") > > >>> from AAA.BBB import Adapter > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named AAA.BBB > > I don't know why I got this. :-( > Any idea? > > > > On Thu, Apr 18, 2013 at 3:07 PM, msutton wrote: > >> What I use is: >> >> import clr >> from System.Reflection import Assembly >> Assembly.LoadWithPartialName('Demo') >> from Render import Demo >> >> where the C# code has namespace Render and public class Demo. >> >> -Manuel >> >> >> On 04/18/2013 02:45 PM, Seungweon Park wrote: >> >> Hi, >> >> I have Adapter.dll with namespace 'AAA.BBB.Adapter" written in C# which >> gives network adapter information. >> I want to call one of method GetSpeed(). I don't know How to create an >> instance in python. >> Would you give me some clue for writing the same python code like below >> powershell script using python.net >> I don't see any sample code which python creates C# class instance. >> >> >> Python >> --------------------------- >> C:\CVS\Pythonnet>npython >> Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] >> on win32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import os,sys >> >>> >> sys.path.append("c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions") >> >>> sys.path >> ['', 'C:\\Python27\\lib\\site-packages\\paramiko-1.10.0-py2.7.egg', >> 'C:\\CVS\\Python\\libs', 'C:\\Windows\\system32\\pyt >> hon27.zip', 'C:\\Python27\\Lib', 'C:\\Python27\\DLLs', >> 'C:\\Python27\\Lib\\lib-tk', 'C:\\CVS\\Pythonnet', 'C:\\Python27' >> , 'C:\\Python27\\lib\\site-packages', >> 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\', >> 'c:\\cvs\\powershelliteexam >> ple\\networktestlibrary\\iteextensions'] >> >>> import clr >> >>> clr.FindAssembly("Adapter") >> >> u'c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions\\Adapter.dll' >> >>> clr.AddReference("Adapter") >> >> >> I don't know how to create an instance of Adapter. >> >> >> Thank you, >> Spark. >> >> >> Powershell >> ---------------------------- >> PS C:\CVS\PowershellITEExample> Import-Module .\LoadAdapter.psd1 >> PS C:\CVS\PowershellITEExample> $adapter = New-object -type >> "AAA.BBB.Adapter" >> PS C:\CVS\PowershellITEExample> $ret = $adapter.GetAdapter("TestAdapter", >> "oids.xml") >> PS C:\CVS\PowershellITEExample> $ret.Passed >> True >> PS C:\CVS\PowershellITEExample> $baseAdapter = $ret.FunctionReturnValue >> PS C:\CVS\PowershellITEExample> $baseAdapter.GetSpeed() >> >> Passed : True >> Failed : False >> Errored : False >> Status : Pass >> Description : Speed retrieved successfully. >> FunctionReturnValue : auto >> >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.orghttp://mail.python.org/mailman/listinfo/pythondotnet >> >> >> > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.orghttp://mail.python.org/mailman/listinfo/pythondotnet > > > -- > Stephen P. Lepisto > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: From swpark71 at gmail.com Sat Apr 20 00:47:52 2013 From: swpark71 at gmail.com (Seungweon Park) Date: Fri, 19 Apr 2013 15:47:52 -0700 Subject: [Python.NET] How to create an instance of C# from pythonnet? In-Reply-To: References: <51706EB9.2000309@ucsd.edu> <5170C4B4.4030806@otakuworld.com> Message-ID: I think I resolved the issue which I need to import reference dlls prior to import "from Network.Common import *". Common uses many refereces from external *.dlls, once I imported all, then I can import Common dll and use correctly. Thank you for your helps. Spark. On Fri, Apr 19, 2013 at 10:45 AM, Seungweon Park wrote: > Thank you for the replies. > > Now, I recompiled Python.Net with .Net 4.0 and get below working with > simple AAA.BBB.Adapter after reading > > > http://stackoverflow.com/questions/14520888/clr-addreferenceexample-file-unable-to-find-assembly?rq=1 > > http://stackoverflow.com/questions/13259617/python-for-net-unable-to-find-assembly-error?rq=1 > http://sourceforge.net/p/pythonnet/bugs/17/ > http://sourceforge.net/p/pythonnet/bugs/18/ > > > Now I have below sample code(Adapter.proj has two c# files), and > experimented > > Class1.cs > ----------- > namespace AAA.BBB.CCC > { > > public class Adapter > { > public string Function1() > { > return "AAA.BBB.CCC: Adapter Function1 Called"; > } > public void Function2() > { > Console.WriteLine("AAA.BBB.CCC: Adapter Function2"); > } > } > > public class Network > { > public string Function1() > { > return "AAA.BBB.CCC: Network Function1 called"; > } > > public void Function2() > { > Console.WriteLine("AAA.BBB.CCC: Network Function2"); > } > } > } > > namespace AAA.BBB > { > public class Adapter > { > public string Function1() > { > return "AAA.BBB: Adapter Function1 Called"; > } > public void Function2() > { > Console.WriteLine("AAA.BBB: Adapter Function2"); > } > } > > public class Network > { > public string Function1() > { > return "AAA.BBB: Network Function1 called"; > } > > public void Function2() > { > Console.WriteLine("AAA.BBB: Network Function2"); > } > } > > } > > Class2.cs > ----------- > namespace AAA.CCC > { > public class Adapter > { > public string Function1() > { > return "AAA.CCC: Adapter Function1 Called"; > } > public void Function2() > { > Console.WriteLine("AAA.CCC: Adapter Function2"); > } > } > } > > Then, I got below. It seems working great. > > C:\Automation\PythonNet>nPython.exe > Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] > on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys > >>> sys.path.append("c:\\automation\\pythonnet") > >>> import clr > >>> clr.FindAssembly("Adapter") > u'Adapter.dll' > >>> clr.AddReference("Adapter") > > >>> adapter1 = Adapter() > Traceback (most recent call last): > File "", line 1, in > NameError: name 'Adapter' is not defined > >>> from AAA.BBB.CCC import Adapter > >>> from AAA.BBB.CCC import * > >>> adapter1 = Adapter() > >>> adapter1.Function1() > u'AAA.BBB.CCC: Adapter Function1 Called' > >>> adapter1.Function2() > AAA.BBB.CCC: Adapter Function2 > >>> network1 = Network() > >>> network1.Function1() > u'AAA.BBB.CCC: Network Function1 called' > >>> from AAA.CCC import * > >>> adapter1.Function1() > u'AAA.BBB.CCC: Adapter Function1 Called' > >>> adapter1 = Adapter() > >>> adapter1.Function1() > u'AAA.CCC: Adapter Function1 Called' > >>> > > My questions are > > 1. I don't know how to specify different namespace of class when creating > an instance. > 2. The class that I already have has similar above layout in a project. > Common project has many class files in it, and each class has different > name space and class name. > AddReference('Common') looks working and loaded, but can't import. > > >>> clr.AddReference('Common') > > >>> from Network import * > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named Network > >>> from Network.Common import * > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named Network.Common > >>> > > Difference is that Common project has [Serializable] and enabled "Make > assembly COM-Visible" > > [Serializable] > [Description("SimpleDictionary")] > public class SimpleDictionary : ISimpleDictionary > { > ... > } > > Any thoughts? > Wonder if there is a way to list available class after AddReference(). > > Thanks, > Spark. > > > > On Thu, Apr 18, 2013 at 9:14 PM, Stephen P. Lepisto < > stephenp at otakuworld.com> wrote: > >> Try this from python with pythonNet installed (the current directory is >> assumed to contain Adapter.dll): >> >> import clr >> clr.AddReference("Adapter") # Load the Adapter.dll >> from AAA.BBB import Adapter # Get the Adapter class type >> adapter = Adapter() # Create instance of the Adapter class >> adapter.GetSpeed() # Call the method >> >> >> >> On 4/18/2013 3:42 PM, Seungweon Park wrote: >> >> Thank you for the reply. >> >> I did >> >> >>> import clr >> >>> from System.Reflection import Assembly >> >>> Assembly.LoadWithPartialName("Adapter") >> >> >>> from AAA.BBB import Adapter >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: No module named AAA.BBB >> >> I don't know why I got this. :-( >> Any idea? >> >> >> >> On Thu, Apr 18, 2013 at 3:07 PM, msutton wrote: >> >>> What I use is: >>> >>> import clr >>> from System.Reflection import Assembly >>> Assembly.LoadWithPartialName('Demo') >>> from Render import Demo >>> >>> where the C# code has namespace Render and public class Demo. >>> >>> -Manuel >>> >>> >>> On 04/18/2013 02:45 PM, Seungweon Park wrote: >>> >>> Hi, >>> >>> I have Adapter.dll with namespace 'AAA.BBB.Adapter" written in C# >>> which gives network adapter information. >>> I want to call one of method GetSpeed(). I don't know How to create an >>> instance in python. >>> Would you give me some clue for writing the same python code like below >>> powershell script using python.net >>> I don't see any sample code which python creates C# class instance. >>> >>> >>> Python >>> --------------------------- >>> C:\CVS\Pythonnet>npython >>> Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit >>> (Intel)] on win32 >>> Type "help", "copyright", "credits" or "license" for more information. >>> >>> import os,sys >>> >>> >>> sys.path.append("c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions") >>> >>> sys.path >>> ['', 'C:\\Python27\\lib\\site-packages\\paramiko-1.10.0-py2.7.egg', >>> 'C:\\CVS\\Python\\libs', 'C:\\Windows\\system32\\pyt >>> hon27.zip', 'C:\\Python27\\Lib', 'C:\\Python27\\DLLs', >>> 'C:\\Python27\\Lib\\lib-tk', 'C:\\CVS\\Pythonnet', 'C:\\Python27' >>> , 'C:\\Python27\\lib\\site-packages', >>> 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\', >>> 'c:\\cvs\\powershelliteexam >>> ple\\networktestlibrary\\iteextensions'] >>> >>> import clr >>> >>> clr.FindAssembly("Adapter") >>> >>> u'c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions\\Adapter.dll' >>> >>> clr.AddReference("Adapter") >>> >>> >>> I don't know how to create an instance of Adapter. >>> >>> >>> Thank you, >>> Spark. >>> >>> >>> Powershell >>> ---------------------------- >>> PS C:\CVS\PowershellITEExample> Import-Module .\LoadAdapter.psd1 >>> PS C:\CVS\PowershellITEExample> $adapter = New-object -type >>> "AAA.BBB.Adapter" >>> PS C:\CVS\PowershellITEExample> $ret = >>> $adapter.GetAdapter("TestAdapter", "oids.xml") >>> PS C:\CVS\PowershellITEExample> $ret.Passed >>> True >>> PS C:\CVS\PowershellITEExample> $baseAdapter = $ret.FunctionReturnValue >>> PS C:\CVS\PowershellITEExample> $baseAdapter.GetSpeed() >>> >>> Passed : True >>> Failed : False >>> Errored : False >>> Status : Pass >>> Description : Speed retrieved successfully. >>> FunctionReturnValue : auto >>> >>> >>> _________________________________________________ >>> Python.NET mailing list - PythonDotNet at python.orghttp://mail.python.org/mailman/listinfo/pythondotnet >>> >>> >>> >> >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.orghttp://mail.python.org/mailman/listinfo/pythondotnet >> >> >> -- >> Stephen P. Lepisto >> >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> http://mail.python.org/mailman/listinfo/pythondotnet >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mjoubert at blackberry.com Tue Apr 30 13:25:34 2013 From: mjoubert at blackberry.com (Morne Joubert) Date: Tue, 30 Apr 2013 11:25:34 +0000 Subject: [Python.NET] Using embedded structs Message-ID: Hi, I am new at Paython and Python.NET and have been trying to use my own .NET assemblies. I have been able to get going with mostly but cannot get passed using C# structs. I have a class with an embedded struct public class Log { public class PageManager { public struct Page { public long byteEnd; public long byteStart; public int indexEnd; public int indexStart; public long timestampTick; public DecodedItem firstItem; public DecodedItem lastItem; } } } In my C# code I just use Log.PageManager.Page but I cannot figure out how to create a Page object in Python. (I need to pass a Page object as an argument to a method.) Is this possible ? Thanks Morn? Joubert --------------------------------------------------------------------- This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kmike at hotbox.ru Tue Apr 30 04:15:47 2013 From: kmike at hotbox.ru (Mikhail Karmyshev) Date: Tue, 30 Apr 2013 06:15:47 +0400 Subject: [Python.NET] Importing .NET assembly with "." (dot) in the name Message-ID: <22c2ac2d78082813352d84f7103c1175d58196e0@mail.qip.ru> Hello, Sorry for possibly dumb question, but is it possible to import an assembly with "." (dot) in the name ? Without dot, for example "SlimDX.dll" - AddReference works and import works too. But for "Accord.Imaging.dll" - AddReference is OK, but import fails: >>> import Accord.Imaging Traceback (most recent call last): File "", line 1, in ImportError: No module named Accord Is there a workaround for this or am I doing something wrong? Any help appreciated. Mikhail From mtigges at gmail.com Tue Apr 30 17:21:41 2013 From: mtigges at gmail.com (Mark Tigges) Date: Tue, 30 Apr 2013 08:21:41 -0700 Subject: [Python.NET] Importing .NET assembly with "." (dot) in the name In-Reply-To: <22c2ac2d78082813352d84f7103c1175d58196e0@mail.qip.ru> References: <22c2ac2d78082813352d84f7103c1175d58196e0@mail.qip.ru> Message-ID: import is namespace on the AddReference. The import hooks look in the dll's that you've referenced, and search for namespaces as per the argument to Accord. So, you shouldn't import the dll name. If the assembly defines the namespace: namespace AccordImaging { ....... Then, you should: import AccordImaging After you AddReference On Mon, Apr 29, 2013 at 7:15 PM, Mikhail Karmyshev wrote: > Hello, > Sorry for possibly dumb question, but is it possible to import an assembly > with "." (dot) in the name ? > Without dot, for example "SlimDX.dll" - AddReference works and import > works too. > But for "Accord.Imaging.dll" - AddReference is OK, but import fails: > >>> import Accord.Imaging > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named Accord > > Is there a workaround for this or am I doing something wrong? > Any help appreciated. > Mikhail > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kmike at hotbox.ru Tue Apr 30 18:01:24 2013 From: kmike at hotbox.ru (Mikhail Karmyshev) Date: Tue, 30 Apr 2013 20:01:24 +0400 Subject: [Python.NET] =?utf-8?q?Importin=C2=ADg_=2ENET_assembly_with_=22?= =?utf-8?b?LiIgwq0oZG90KSBpbiB0aGUgbmFtZQ==?= In-Reply-To: References: Message-ID: <72857c6cf87479c01ce816db798b0777dee3447c@mail.qip.ru> Mark, thank you for your help. Too bad that the original assembly which I am trying to use has namespace with "." in it: namespace Accord.Imaging{ } So in C# "using Accord.Imaging'" works fine, but how to deal with it from Python? Sure, I can write a "wrapper" application without dots in namespace, I tested it and it works. But of course cleaner solution would be nice. ??? 30 ??? 2013 22:21:42 +0700, Mark Tigges ???????: > import is namespace on the AddReference. > > The import hooks look in the dll's that you've referenced, and search for namespaces as per the argument to Accord. So, you shouldn't import the dll name. If the assembly defines the namespace: > > namespace AccordImaging > { > ....... > > Then, you should: > > import AccordImaging > > After you AddReference > > On Mon, Apr 29, 2013 at 7:15 PM, Mikhail Karmyshev wrote: > Hello, > Sorry for possibly dumb question, but is it possible to import an assembly with "." (dot) in the name ? > Without dot, for example "SlimDX.dll" - AddReference works and import works too. > But for "Accord.Imaging.dll" - AddReference is OK, but import fails: > >>> import Accord.Imaging > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named Accord > > Is there a workaround for this or am I doing something wrong? > Any help appreciated. > Mikhail > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -- From greenhat at gmail.com Tue Apr 30 18:50:50 2013 From: greenhat at gmail.com (Jeremy Chiu) Date: Tue, 30 Apr 2013 09:50:50 -0700 Subject: [Python.NET] Fwd: A question about pythonnet + pyinstaller In-Reply-To: References: Message-ID: Hi All, So, the issue I'm running into is in combining pyinstaller with pythonnet. I'll describe my current situation. Hopefully it isn't too long and you have some insight. I have a little bit of UI put together via Windows forms. I can run it fine via pythonnet by doing "clr.AddReference('System.Windows.Forms')" to load the assembly, doing "from System.Windows.Forms import Application" to get at the Application class so I can do Application.Run(myform), and by adding the location of my little UI dll to the python path and importing classes I need from there. I can also happily do all this after building everything into an exe via pyinstaller. I did have to jump thru a few pyinstaller hoops to add my little dll to the package pyinstaller builds as well as Python.Runtime.dll. The path to the location where those are added is appended to pythonpath auto-magically by pyinstaller so they're found just fine. So then I found that I needed to get at System.ComponentModel.BindingList and System.Drawing.Bitmap. I thought all I'd have to do would be "clr.AddReference('System')" and "clr.AddReference('System.Drawing')" and then import BindingList from System.ComponentModel and Bitmap from System.Drawing. This worked fine when running from pure python but was unhappy running from the pyinstaller-built exe. In the exe it complains that it can't import BindingList (or Bitmap if I comment out BindingList). I can make it work in the exe if I use a direct import instead of a 'from' style import. So if I do "import System.ComponentModel.BindingList" instead of "from System.ComponentModel import BindingList" it works. However I don't think I should have to do a direct import and doing so gives me problems in the pure python world. I actually don't even understand how the System.Windows.Forms assembly is found in the exe scenario. I don't add the System.Windows.Forms.dll to the package that pyinstaller builds and yet it works just fine which implies that it is being found elsewhere but I don't understand how (nor why it doesn't find the other assemblies that I also want). Sorry for the long email. Hopefully you have some insight. Hopefully you know what pyinstaller is so that the majority of this email makes some sense =p Thanks for any leads you can provide, Jeremy -------------- next part -------------- An HTML attachment was scrubbed... URL: From greenhat at gmail.com Tue Apr 30 18:53:06 2013 From: greenhat at gmail.com (Jeremy Chiu) Date: Tue, 30 Apr 2013 09:53:06 -0700 Subject: [Python.NET] A question about pythonnet + pyinstaller Message-ID: Hi All, So, the issue I'm running into is in combining pyinstaller with pythonnet. I'll describe my current situation. Hopefully it isn't too long and you have some insight. I have a little bit of UI put together via Windows forms. I can run it fine via pythonnet by doing "clr.AddReference('System.Windows.Forms')" to load the assembly, doing "from System.Windows.Forms import Application" to get at the Application class so I can do Application.Run(myform), and by adding the location of my little UI dll to the python path and importing classes I need from there. I can also happily do all this after building everything into an exe via pyinstaller. I did have to jump thru a few pyinstaller hoops to add my little dll to the package pyinstaller builds as well as Python.Runtime.dll. The path to the location where those are added is appended to pythonpath auto-magically by pyinstaller so they're found just fine. So then I found that I needed to get at System.ComponentModel.BindingList and System.Drawing.Bitmap. I thought all I'd have to do would be "clr.AddReference('System')" and "clr.AddReference('System.Drawing')" and then import BindingList from System.ComponentModel and Bitmap from System.Drawing. This worked fine when running from pure python but was unhappy running from the pyinstaller-built exe. In the exe it complains that it can't import BindingList (or Bitmap if I comment out BindingList). I can make it work in the exe if I use a direct import instead of a 'from' style import. So if I do "import System.ComponentModel.BindingList" instead of "from System.ComponentModel import BindingList" it works. However I don't think I should have to do a direct import and doing so gives me problems in the pure python world. I actually don't even understand how the System.Windows.Forms assembly is found in the exe scenario. I don't add the System.Windows.Forms.dll to the package that pyinstaller builds and yet it works just fine which implies that it is being found elsewhere but I don't understand how (nor why it doesn't find the other assemblies that I also want). Sorry for the long email. Hopefully you have some insight. Hopefully you know what pyinstaller is so that the majority of this email makes some sense =p Thanks for any leads you can provide, Jeremy -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at fie.us Tue Apr 30 22:22:59 2013 From: brad at fie.us (brad at fie.us) Date: Tue, 30 Apr 2013 16:22:59 -0400 Subject: [Python.NET] =?utf-8?q?Importin=C2=ADg_=2ENET_assembly_with_=22?= =?utf-8?b?LiIgwq0oZG90KSBpbiB0aGUgbmFtZQ==?= In-Reply-To: <72857c6cf87479c01ce816db798b0777dee3447c@mail.qip.ru> References: <72857c6cf87479c01ce816db798b0777dee3447c@mail.qip.ru> Message-ID: You are confused. Mark was pointing out that since an assembly is not necessarily named on disk, the same as the namespaces within it, you need to AddReference the assembly on disk, and THEN import the namespace. And the namespace may not be named the same as the reference. PythonNet is perfectly capable of importing a nested dot delimited namespace. """ fiellcmbp01:pythonnet bfriedman$ cd system_2.7-ucs2_fie-mono-64_osx_2.10.9/ fiellcmbp01:system_2.7-ucs2_fie-mono-64_osx_2.10.9 bfriedman$ ls Python.Runtime.dll clr.pyd Python.Runtime.dll.config clr.so fiellcmbp01:system_2.7-ucs2_fie-mono-64_osx_2.10.9 bfriedman$ python Python 2.7.2 (default, Oct 11 2012, 20:14:37) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import clr >>> import System.IO >>> System.IO.Path.Combine('foo','bar') u'foo/bar' >>> """ -brad On Apr 30, 2013, at 12:01 PM, Mikhail Karmyshev wrote: > Mark, thank you for your help. > Too bad that the original assembly which I am trying to use has namespace with "." in it: > namespace Accord.Imaging{ > } > > So in C# "using Accord.Imaging'" works fine, but how to deal with it from Python? > Sure, I can write a "wrapper" application without dots in namespace, I tested it and it works. > But of course cleaner solution would be nice. > > > ??? 30 ??? 2013 22:21:42 +0700, Mark Tigges ???????: >> import is namespace on the AddReference. >> >> The import hooks look in the dll's that you've referenced, and search for namespaces as per the argument to Accord. So, you shouldn't import the dll name. If the assembly defines the namespace: >> >> namespace AccordImaging >> { >> ....... >> >> Then, you should: >> >> import AccordImaging >> >> After you AddReference >> >> On Mon, Apr 29, 2013 at 7:15 PM, Mikhail Karmyshev wrote: >> Hello, >> Sorry for possibly dumb question, but is it possible to import an assembly with "." (dot) in the name ? >> Without dot, for example "SlimDX.dll" - AddReference works and import works too. >> But for "Accord.Imaging.dll" - AddReference is OK, but import fails: >>>>> import Accord.Imaging >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: No module named Accord >> >> Is there a workaround for this or am I doing something wrong? >> Any help appreciated. >> Mikhail >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> http://mail.python.org/mailman/listinfo/pythondotnet > > -- > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet