From amod.kulkarni at neilsoft.com Mon Jan 3 08:37:32 2005 From: amod.kulkarni at neilsoft.com (Amod Kulkarni) Date: Mon Jan 3 15:28:24 2005 Subject: [Python.NET] Calling C# from Python 2.3 Message-ID: Hi, I know PythonNet has been specially designed to handle .NET/CLR compatibility but because of some other restrictions I want to use Python 2.3 to access a C# function. First of all is it possible? I am trying with following piece of code in C# (Server app) and python (client app). This is a class library in C# which is compiled and registered with following commands. csc /target:library Class1.cs regasm Try2005.dll /tlb:Try2005.tlb using System; using System.Runtime.InteropServices; namespace Try2005 { public class TestingCSBC { [Guid("1EB394AB-2D4A-4a52-9F22-E8ACAED4800F")] public interface IManagedInterface { int PrintHi(string name); } [Guid("2FD76301-489A-4dc3-BF6B-5DF6FCE96CB8")] public class InterfaceImplementation : IManagedInterface { public int PrintHi(string name) { Console.WriteLine("Hello, {0}!", name); //TestCSBCClass obj = new TESTDLLCOMLib.TestCSBCClass(); //obj.Displaymessage("In C# application!!"); return 33; } } } } Python code: import win32com.client try: serverObj = win32com.client.Dispatch("Try2005.TestingCSBC") except Exception,e: print "Dispatch error",e try: serverObj.PrintHi("But will it work on Tribon??") except Exception,e: print "Error while Calling C# function",e After running the above Py script I am getting following error output. Dispatch error (-2147024894, 'The system cannot find the file specified.', None, None) Error while Calling C# function name 'serverObj' is not defined Any pointers would be greatly appreciated. Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20050103/bbec1a95/attachment-0001.htm From brian at zope.com Mon Jan 3 21:23:36 2005 From: brian at zope.com (Brian Lloyd) Date: Mon Jan 3 21:23:45 2005 Subject: [Python.NET] Calling C# from Python 2.3 In-Reply-To: Message-ID: Hi Amod - Is the main issue the fact that you have to use Python 2.3? If so, you could use the beta 3 release (which was based on 2.3), or see the README.txt for instructions on building the b4 release for Python 2.3. In any case, you should be able to just copy Python.Runtime.dll and CLR.dll from the PythonNet directory to the root directory of your python installation (presuming they were built against 2.3), and then 'import CLR' from your exising Python... Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com -----Original Message----- From: pythondotnet-bounces@python.org [mailto:pythondotnet-bounces@python.org]On Behalf Of Amod Kulkarni Sent: Monday, January 03, 2005 2:38 AM To: pythondotnet@python.org Subject: [Python.NET] Calling C# from Python 2.3 Hi, I know PythonNet has been specially designed to handle .NET/CLR compatibility but because of some other restrictions I want to use Python 2.3 to access a C# function. First of all is it possible? I am trying with following piece of code in C# (Server app) and python (client app). This is a class library in C# which is compiled and registered with following commands. csc /target:library Class1.cs regasm Try2005.dll /tlb:Try2005.tlb using System; using System.Runtime.InteropServices; namespace Try2005 { public class TestingCSBC { [Guid("1EB394AB-2D4A-4a52-9F22-E8ACAED4800F")] public interface IManagedInterface { int PrintHi(string name); } [Guid("2FD76301-489A-4dc3-BF6B-5DF6FCE96CB8")] public class InterfaceImplementation : IManagedInterface { public int PrintHi(string name) { Console.WriteLine("Hello, {0}!", name); //TestCSBCClass obj = new TESTDLLCOMLib.TestCSBCClass(); //obj.Displaymessage("In C# application!!"); return 33; } } } } Python code: import win32com.client try: serverObj = win32com.client.Dispatch("Try2005.TestingCSBC") except Exception,e: print "Dispatch error",e try: serverObj.PrintHi("But will it work on Tribon??") except Exception,e: print "Error while Calling C# function",e After running the above Py script I am getting following error output. Dispatch error (-2147024894, 'The system cannot find the file specified.', None, None) Error while Calling C# function name 'serverObj' is not defined Any pointers would be greatly appreciated. Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20050103/56a764cf/attachment.html From jvm_cop at spamcop.net Tue Jan 4 18:25:56 2005 From: jvm_cop at spamcop.net (J. Merrill) Date: Tue Jan 4 18:23:58 2005 Subject: [Python.NET] Calling C# from Python 2.3 In-Reply-To: Message-ID: <4.3.2.7.2.20050104115934.093b2088@mail.comcast.net> The docn says that any .NET class to be used from COM must have a public no-parameters constructor. I don't see one in any of the classes you defined. Nesting classes the way you have is not, I don't think, going to be compatible with being called from COM. The class you seem to be asking COM to create (the outer class) is not one that has a PrintHi method. Also, some samples suggest that you might want to use more attributes: [ClassInterface(ClassInterfaceType.AutoDispatch)] [ProgID("Try2005.TestingCSBC")] on the class you want to be callable. I don't think those are required, but they'll increase the explicit info that you're providing to the code that builds the COM-callable-wrapper (the mechanism that exposes the .NET code to COM) for your class. However, for each of those issues, I'm surprised that you're getting the message "cannot find the file specified." You could try using FileMon (from sysinternals.com) to figure out what file it's looking for that's not being found; you could try calling this from VB or VBA and see if you've got the same problem; you could use OLEView.exe (or raw registry examination) to look at what the COM defn of your class is. I'm sure that you can do simple calls to simple .NET objects from Python 2.x without using Python.NET -- but if you can't use the COM object from VB (when declaring the variable as type Object), you won't be able to use it via Python's win32com.client.Dispatch. You might want to look at (perhaps wrapped) http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/pywin32/html/com/win32com/HTML/QuickStartClientCom.html for info about using makepy.py to generate a Python "wrapper class" so that you don't have to work with a "raw" COM IDispatch. (If you change 2.3 to 2.4 you get some more info, but apparently nothing about functionality only in 2.3.) Good luck. At 02:37 AM 1/3/2005, Amod Kulkarni wrote >Hi, > >I know PythonNet has been specially designed to handle .NET/CLR compatibility but because of some other restrictions I want to use Python 2.3 to access a C# function. [snip] J. Merrill / Analytical Software Corp -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20050104/96222b29/attachment.htm From cfaulhaber at codealchemy.org Sun Jan 16 01:21:11 2005 From: cfaulhaber at codealchemy.org (Chris Faulhaber) Date: Sun Jan 16 01:20:47 2005 Subject: [Python.NET] Problem when chaining script calls through CLR classes Message-ID: <41E9B377.2070007@codealchemy.org> Hi folks, I've run across what I think may be a bug when I chain a script call through my own application. I'm using 1.0-beta4 on Windows XP with an installation of Python 2.4. The sequence I use to reproduce the problem is fairly simple: 1) Execute some Python code either through PyObject.InvokeMethod, or PythonEngine.RunSimpleString. 2) From the executed Python code, call into a CLR class. 3) From the CLR class, execute Python code again. When this happens, I get a NullReferenceException with this stack trace: at Python.Runtime.Runtime.PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw) at Python.Runtime.PyObject.Invoke(PyObject[] args) at Python.Runtime.PyObject.InvokeMethod(String name, PyObject[] args) at Here is some example code that demonstrates the issue: using System; using Python.Runtime; namespace PDNBug { public class Example { [STAThread] static void Main(string[] args) { PythonEngine.Initialize(); PythonEngine.RunSimpleString("from CLR.PDNBug import Example\nExample.FirstCall()"); } public static void FirstCall () { Console.WriteLine("First call succeeded."); PythonEngine.RunSimpleString("from CLR.PDNBug import Example\nExample.SecondCall()"); } public static void SecondCall () { Console.WriteLine("Second call succeeded."); } } } Note that this example uses RunSimpleString to demonstrate the effect, but the above stack trace came from some more complex code that primarily uses code objects generated through Python compile(). When the example code is executed, I receive the following output: First call succeeded. Traceback (most recent call last): File "", line 2, in ? : Object reference not set to an instance of an object. So is this issue a bug, or should I simply not be doing what I'm doing? Regards, Chris Faulhaber From pythondotnet at python.org Mon Jan 17 22:01:33 2005 From: pythondotnet at python.org (Collector: Python for .NET Issue ...) Date: Mon Jan 17 22:03:19 2005 Subject: [Python.NET] [PythonNet] 2/ 2 Resolve "Float ValueError in different regional settings (Windows XP)" Message-ID: <20050117210133.6899C20327E@mail.zope.org> Issue #2 Update (Resolve) "Float ValueError in different regional settings (Windows XP)" Status Resolved, Testing/bug medium To followup, visit: http://zope.org/Members/Brian/PythonNet/Collector/2 ============================================================== = Resolve - Entry #2 by Brian on Jan 17, 2005 4:01 pm Status: Pending => Resolved This is fixed for the next release. Thanks for the report! --Brian ________________________________________ = Request - Entry #1 by Anonymous User on Dec 15, 2004 2:51 am started runtests.py some test fail with a message like: ERROR: Test single fields. ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\Downloads\python\PythonNet-1.0-beta4\PythonNet-1.0-beta4\tests\python \test_field.py", line 363, in testSingleField self.failUnless(object.SingleField == 1.1) ValueError: invalid literal for float(): 1,1 The regional settings (German): decimal symbol: , digit grouping symbol: . ============================================================== From bhanu.nukala at neilsoft.com Thu Jan 20 06:59:56 2005 From: bhanu.nukala at neilsoft.com (bhanu.nukala) Date: Thu Jan 20 15:27:50 2005 Subject: [Python.NET] example of calling Python from C# with simple object Message-ID: <000001c4feb5$44d5e260$320300c0@hp100> hai MBarclay, I am Bhanu Prakash from Pune, India. I am working as a trainee software engineer. I am currently working on python and c#.can you find me more help on python and c#. can you find some tutors on how to implement python in C# and how to implement C# in python. I saw some links like example of calling python from c# etc...In that your examples are very good but for a fresher candidate that is difficult to understand. So please send some more details on python and c#. In your examples your used invoke method. What is the purpose of that function and in which cases the function is able to use. Tell me the functions and description of that functions which are useful in python and c# Ok I am waiting for your reply With regards Bhanu Prakash Nukala, Neilsoft Limited, mailto:bhanu.nukala@neilsoft.com Phone : 91-20-24464455/66/77 Extn:282 Mobile #:9850757838 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20050120/9ef8ed82/attachment.html From stan at phidani.be Thu Jan 20 18:58:00 2005 From: stan at phidani.be (Stan Pinte) Date: Thu Jan 20 19:02:01 2005 Subject: [Python.NET] managed exception stack trace. Message-ID: <41EFF128.2040702@phidani.be> hello, I am using pythonNet with a great pleasure, thanks a lot for that piece of work. IMHO, a wiki would be very very useful for this project, as I would be ready to contribute... One question: How do I print out managed exceptions full stack trace? thanks, Stan. From brian at zope.com Thu Jan 20 19:48:01 2005 From: brian at zope.com (Brian Lloyd) Date: Thu Jan 20 19:48:13 2005 Subject: [Python.NET] managed exception stack trace. In-Reply-To: <41EFF128.2040702@phidani.be> Message-ID: > I am using pythonNet with a great pleasure, thanks a lot for that piece > of work. > > IMHO, a wiki would be very very useful for this project, as I would be > ready to contribute... > > One question: > > How do I print out managed exceptions full stack trace? Hi Stan - A trick you might be able to use is: print CLR.System.Environment.StackTrace Exceptions are in kind of an odd state right now - the C Python runtime really wants exceptions to be old-style Python classes, and the fact that managed exceptions aren't causes some problems in the current version of Python for .NET. I'm still hoping to find a sneaky way around it or successfully lobby the Python devs to remove this restriction for a future Python version. Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From brian at zope.com Thu Jan 20 21:23:52 2005 From: brian at zope.com (Brian Lloyd) Date: Thu Jan 20 21:24:04 2005 Subject: [Python.NET] Problem when chaining script calls through CLR classes In-Reply-To: <41E9B377.2070007@codealchemy.org> Message-ID: > So is this issue a bug, or should I simply not be doing what I'm doing? Hi Chris - Certainly what you're trying to do is intended to work - I'll have to do some digging to find out why its not. Thanks for the clear test case, BTW ;) Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com > -----Original Message----- > From: pythondotnet-bounces@python.org > [mailto:pythondotnet-bounces@python.org]On Behalf Of Chris Faulhaber > Sent: Saturday, January 15, 2005 7:21 PM > To: pythondotnet@python.org > Subject: [Python.NET] Problem when chaining script calls through CLR > classes > > > Hi folks, > > I've run across what I think may be a bug when I chain a script call > through my own application. I'm using 1.0-beta4 on Windows XP with an > installation of Python 2.4. The sequence I use to reproduce the problem > is fairly simple: > 1) Execute some Python code either through PyObject.InvokeMethod, or > PythonEngine.RunSimpleString. > 2) From the executed Python code, call into a CLR class. > 3) From the CLR class, execute Python code again. > > When this happens, I get a NullReferenceException with this stack trace: > at Python.Runtime.Runtime.PyObject_Call(IntPtr pointer, IntPtr args, > IntPtr kw) > at Python.Runtime.PyObject.Invoke(PyObject[] args) > at Python.Runtime.PyObject.InvokeMethod(String name, PyObject[] args) > at > > Here is some example code that demonstrates the issue: > using System; > using Python.Runtime; > > namespace PDNBug { > public class Example { > [STAThread] > static void Main(string[] args) { > PythonEngine.Initialize(); > PythonEngine.RunSimpleString("from CLR.PDNBug import > Example\nExample.FirstCall()"); > } > > public static void FirstCall () { > Console.WriteLine("First call succeeded."); > PythonEngine.RunSimpleString("from CLR.PDNBug import > Example\nExample.SecondCall()"); > } > > public static void SecondCall () { > Console.WriteLine("Second call succeeded."); > } > } > } > > Note that this example uses RunSimpleString to demonstrate the effect, > but the above stack trace came from some more complex code that > primarily uses code objects generated through Python compile(). When > the example code is executed, I receive the following output: > First call succeeded. > Traceback (most recent call last): > File "", line 2, in ? > : Object > reference not set to an instance of an object. > > So is this issue a bug, or should I simply not be doing what I'm doing? > > Regards, > Chris Faulhaber > _________________________________________________ > Python.NET mailing list - PythonDotNet@python.org > http://mail.python.org/mailman/listinfo/pythondotnet > From bksasha at zahav.net.il Mon Jan 24 23:24:31 2005 From: bksasha at zahav.net.il (bksasha@zahav.net.il) Date: Mon Jan 24 23:19:27 2005 Subject: [Python.NET] calling methods from Zope Message-ID: <01c801c50263$87bd86d0$0500000a@gate> Hi I am trying to use Python Net with Zope. I successfully compiled Zope for Python 2.4. The strange issue I am facing is that when I use Python interpreter or run scripts from command prompt everything works fine, but when I use external methods from Zope I cant call any method on CLR objects. Properties, constructors work fine, but calling any method (even void without parameters) hangs the system. What can be the reason? Thanks Alexander -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20050125/4d404a75/attachment.htm From bksasha at zahav.net.il Mon Jan 24 23:38:10 2005 From: bksasha at zahav.net.il (bksasha@zahav.net.il) Date: Mon Jan 24 23:30:54 2005 Subject: [Python.NET] calling methods from Zope Message-ID: <01e301c50265$62248480$0500000a@gate> Hi I am trying to use Python Net with Zope. I successfully compiled Zope for Python 2.4. The strange issue I am facing is that when I use Python interpreter or run scripts from command prompt everything works fine, but when I use external methods from Zope I cant call any method on CLR objects. Properties, constructors work fine, but calling any method (even void without parameters) hangs the system. What can be the reason? Thanks Alexander -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20050125/981a4bdd/attachment.html