From livernsy at e-i.com Thu Jun 1 17:08:21 2006 From: livernsy at e-i.com (LIVERNAIS Sylvie) Date: Thu, 1 Jun 2006 17:08:21 +0200 Subject: [Python.NET] How to run a .py file from C# Message-ID: Hi, I'm a newbie in C# and python and try to run a .py file from a C# program. I tried the same thing from a C++ program using PyRun_SimpleFile and in the console, I could see the python execution (the print from python). Using Python.Runtime.dll from Python.NET, I saw that such a fonction is not available, and should use PythonEngine.ImportModule and PythonEngine.RunString or PythonEngine.RunSimpleString. The thing is that it only works for a command written over one line, but if I have a "def" (which is written over several lines), the RunString doesn't work any more... So how can I run the whole file, and not only line by line ? By the way, what does exactly the ImportModule function ? Maybe the .py file is already executed but I can't see it ? Is there a way to get the output and display it in the console ? Thanks for you answer __ Sylvie LIVERNAIS ___________ Applications Cartes ? Puce EID * : +33 (0) 388 14 28 75 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20060601/28274cce/attachment.html From Radhika.Srivatsa at ngc.com Thu Jun 1 18:52:50 2006 From: Radhika.Srivatsa at ngc.com (Srivatsa, Radhika) Date: Thu, 1 Jun 2006 09:52:50 -0700 Subject: [Python.NET] Using Python to test .NET application In-Reply-To: Message-ID: <2E31CB5D3E672047A7C4D44CB56010C235CF79@XMBCAK04> Hi, I am new to Python and am contemplating of using it to Unit Test the .NET application written in VC++. I know there is documentation of using the Python Unit Testing Framework. Is there anything else (a book or a website) that'd be helpful in walking me through the steps of being able to Unit Test the various VC++ classes and their behavior using Python ? I mean - what is the best way for me to learn how to go about writing a Python program to write Unit Test cases ? Appreciate any info I can get. Thanks --Radhika Radhika Srivatsa UMS Software Development Voice: (858)618-2235 From Brian.Lloyd at revolution.com Thu Jun 1 22:12:34 2006 From: Brian.Lloyd at revolution.com (Brian Lloyd) Date: Thu, 1 Jun 2006 16:12:34 -0400 Subject: [Python.NET] Using Python to test .NET application Message-ID: <65531D426735784F854EE658938A585303C129B2@MI8NYCMAIL03.Mi8.com> Hi Radhika, The Python for .NET unit test suite (in src/tests of the distro) are probably a pretty good example of what you want to do. -Brian > -----Original Message----- > From: pythondotnet-bounces at python.org > [mailto:pythondotnet-bounces at python.org] On Behalf Of > Srivatsa, Radhika > Sent: Thursday, June 01, 2006 12:53 PM > To: pythondotnet at python.org > Subject: [Python.NET] Using Python to test .NET application > > Hi, > > I am new to Python and am contemplating of using it to Unit > Test the .NET application written in VC++. I know there is > documentation of using the Python Unit Testing Framework. Is > there anything else (a book or a > website) that'd be helpful in walking me through the steps of > being able to Unit Test the various VC++ classes and their > behavior using Python ? > I mean - what is the best way for me to learn how to go about > writing a Python program to write Unit Test cases ? > Appreciate any info I can get. > > Thanks > > --Radhika > > Radhika Srivatsa > UMS Software Development > Voice: (858)618-2235 > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > > From Brian.Lloyd at revolution.com Thu Jun 1 22:15:27 2006 From: Brian.Lloyd at revolution.com (Brian Lloyd) Date: Thu, 1 Jun 2006 16:15:27 -0400 Subject: [Python.NET] How to run a .py file from C# Message-ID: <65531D426735784F854EE658938A585303C129CA@MI8NYCMAIL03.Mi8.com> Have you tried using the PythonEngine.RunString (not RunSimpleString) method? Still not as convenient as having a RunFile, but that should do what you need for now. -Brian > -----Original Message----- > From: pythondotnet-bounces at python.org > [mailto:pythondotnet-bounces at python.org] On Behalf Of LIVERNAIS Sylvie > Sent: Thursday, June 01, 2006 11:08 AM > To: pythondotnet at python.org > Subject: [Python.NET] How to run a .py file from C# > > Hi, > > I'm a newbie in C# and python and try to run a .py file from > a C# program. > > I tried the same thing from a C++ program using > PyRun_SimpleFile and in the console, I could see the python > execution (the print from python). > > Using Python.Runtime.dll from Python.NET, I saw that such a > fonction is not available, and should use > PythonEngine.ImportModule and PythonEngine.RunString or > PythonEngine.RunSimpleString. The thing is that it only works > for a command written over one line, but if I have a "def" > (which is written over several lines), the RunString doesn't > work any more... So how can I run the whole file, and not > only line by line ? > > By the way, what does exactly the ImportModule function ? > Maybe the .py file is already executed but I can't see it ? > Is there a way to get the output and display it in the console ? > > Thanks for you answer > > __ Sylvie LIVERNAIS ___________ > Applications Cartes ? Puce > EID > * : +33 (0) 388 14 28 75 > > From max_hung at afatech.com.tw Fri Jun 2 05:16:42 2006 From: max_hung at afatech.com.tw (=?big5?B?bWF4IGh1bmcorHiw6q5pKQ==?=) Date: Fri, 2 Jun 2006 11:16:42 +0800 Subject: [Python.NET] doc for pythondotnet Message-ID: <007a01c685f2$f88e8f30$5c02a8c0@maxhung> Anyone knows where i can find doc or programing guide for pythondotnet?? Thanks! 洪國展 Max Hung 詠發科技 Afa Technologies, Inc. Tel: 886-2-2918-9958 ext. 227 max_hung at afatech.com.tw -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20060602/2b28bd4e/attachment.htm From mc at mclaveau.com Fri Jun 2 08:05:03 2006 From: mc at mclaveau.com (Michel Claveau) Date: Fri, 2 Jun 2006 08:05:03 +0200 Subject: [Python.NET] doc for pythondotnet References: <007a01c685f2$f88e8f30$5c02a8c0@maxhung> Message-ID: <000e01c6860a$7f644330$0701a8c0@PORTABLES> >>>Anyone knows where i can find doc or programing guide for pythondotnet? +1 Michel Claveau From myeates at jpl.nasa.gov Sat Jun 3 01:06:03 2006 From: myeates at jpl.nasa.gov (Mathew Yeates) Date: Fri, 02 Jun 2006 16:06:03 -0700 Subject: [Python.NET] delegate funkiness Message-ID: <4480C45B.7090904@jpl.nasa.gov> Hi Brian I have a delegate in python that returns a bool def returnFalse(): return False However, when this function is called from my c# compiled .Net program it always sees a return value of True. Seen this before? (This is with the latest in svn) Mathew From Brian.Lloyd at revolution.com Mon Jun 5 15:27:31 2006 From: Brian.Lloyd at revolution.com (Brian Lloyd) Date: Mon, 5 Jun 2006 09:27:31 -0400 Subject: [Python.NET] delegate funkiness Message-ID: <65531D426735784F854EE658938A585303CEBB3F@MI8NYCMAIL03.Mi8.com> > I have a delegate in python that returns a bool def returnFalse(): > return False > > However, when this function is called from my c# compiled > .Net program it always sees a return value of True. Seen this before? > (This is with the latest in svn) > > Mathew Strange -- no, I haven't seen anything like that before. But I can reproduce it :( I've added a failing test case and I'll look into it. thx, -Brian From Brian.Lloyd at revolution.com Mon Jun 5 16:14:04 2006 From: Brian.Lloyd at revolution.com (Brian Lloyd) Date: Mon, 5 Jun 2006 10:14:04 -0400 Subject: [Python.NET] delegate funkiness Message-ID: <65531D426735784F854EE658938A585303CEBC88@MI8NYCMAIL03.Mi8.com> Update: I had an unboxing problem in the IL I was generating for delegates with value-type return types. Its fixed in svn for the trunk. It'll get merged to the 1.x branch later when I get a few more things finished. -Brian > -----Original Message----- > From: pythondotnet-bounces at python.org > [mailto:pythondotnet-bounces at python.org] On Behalf Of Brian Lloyd > Sent: Monday, June 05, 2006 9:28 AM > To: Mathew Yeates; pythondotnet at python.org > Subject: Re: [Python.NET] delegate funkiness > > > > I have a delegate in python that returns a bool def returnFalse(): > > return False > > > > However, when this function is called from my c# compiled > .Net program > > it always sees a return value of True. Seen this before? > > (This is with the latest in svn) > > > > Mathew > > Strange -- no, I haven't seen anything like that before. But > I can reproduce it :( > > I've added a failing test case and I'll look into it. > > thx, > > -Brian > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > > From myeates at jpl.nasa.gov Mon Jun 5 18:57:41 2006 From: myeates at jpl.nasa.gov (Mathew Yeates) Date: Mon, 05 Jun 2006 09:57:41 -0700 Subject: [Python.NET] delegate funkiness In-Reply-To: <65531D426735784F854EE658938A585303CEBC88@MI8NYCMAIL03.Mi8.com> References: <65531D426735784F854EE658938A585303CEBC88@MI8NYCMAIL03.Mi8.com> Message-ID: <44846285.9090604@jpl.nasa.gov> Cool. Thanks -Mathew Brian Lloyd wrote: > Update: I had an unboxing problem in the IL I was generating > for delegates with value-type return types. > > Its fixed in svn for the trunk. It'll get merged to the 1.x > branch later when I get a few more things finished. > > -Brian > > >> -----Original Message----- >> From: pythondotnet-bounces at python.org >> [mailto:pythondotnet-bounces at python.org] On Behalf Of Brian Lloyd >> Sent: Monday, June 05, 2006 9:28 AM >> To: Mathew Yeates; pythondotnet at python.org >> Subject: Re: [Python.NET] delegate funkiness >> >> >> >>> I have a delegate in python that returns a bool def returnFalse(): >>> return False >>> >>> However, when this function is called from my c# compiled >>> >> .Net program >> >>> it always sees a return value of True. Seen this before? >>> (This is with the latest in svn) >>> >>> Mathew >>> >> Strange -- no, I haven't seen anything like that before. But >> I can reproduce it :( >> >> I've added a failing test case and I'll look into it. >> >> thx, >> >> -Brian >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> http://mail.python.org/mailman/listinfo/pythondotnet >> >> >> > > > From myeates at jpl.nasa.gov Mon Jun 5 19:53:27 2006 From: myeates at jpl.nasa.gov (Mathew Yeates) Date: Mon, 05 Jun 2006 10:53:27 -0700 Subject: [Python.NET] something broke? Message-ID: <44846F97.9090305@jpl.nasa.gov> I updated to the latest in svn and now I cant import a delegate defined in my csharp code. ????? C# code public delegate void MyDelegate(); python code from mydll import MyDelegate I get "cannot import name MyDelegate". This worked fine before I updated from svn. ????? Mathew From myeates at jpl.nasa.gov Mon Jun 5 21:34:26 2006 From: myeates at jpl.nasa.gov (Mathew Yeates) Date: Mon, 05 Jun 2006 12:34:26 -0700 Subject: [Python.NET] Nevermind: Re: something broke? In-Reply-To: <44846F97.9090305@jpl.nasa.gov> References: <44846F97.9090305@jpl.nasa.gov> Message-ID: <44848742.4030209@jpl.nasa.gov> Can't duplicate. Mathew Yeates wrote: > I updated to the latest in svn and now I cant import a delegate defined > in my csharp code. > ????? > > C# code > public delegate void MyDelegate(); > > python code > from mydll import MyDelegate > > I get "cannot import name MyDelegate". > > This worked fine before I updated from svn. > > ????? > Mathew > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > > From MP at credaris.com Tue Jun 6 12:07:44 2006 From: MP at credaris.com (Matthew Pontefract) Date: Tue, 6 Jun 2006 11:07:44 +0100 Subject: [Python.NET] .NET 2 and hang with AcquireLock Message-ID: <8EE03F7BD203224A972E4A479E6CDE81F50850@cpm01.creditportfolio.com> Hello I have a question pertaining to running Python NET under .NET version 2 which, admittedly, is not the version for which the packages are built. All works just fine - I am using the PythonEngine inside a web service, acquiring the GIL before operations, releasing it in a 'finally' block afterwards. This is fine provided no python exceptions are raised in the Python code. Even though the GIL is released in the C#, a subsequent call to AcquireLock will hang as if waiting for it to be released. No calls to acquirelock have been made between the last call to release the GIL and the call that hangs. Has anyone else had this problem? I am using Python 2.4 Regards Matthew Dr Matthew Pontefract Credaris Portfolio Management ________________________________________ mp at credaris.com T : (44) 207 925 8365 F : (44) 207 925 8399 CPM Advisers Limited Norfolk House 30 Charles II Street London SW1Y 4AE www.credaris.com Regulated by the Financial Services Authority -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20060606/7e980288/attachment.html From Brian.Lloyd at revolution.com Tue Jun 6 15:23:34 2006 From: Brian.Lloyd at revolution.com (Brian Lloyd) Date: Tue, 6 Jun 2006 09:23:34 -0400 Subject: [Python.NET] .NET 2 and hang with AcquireLock Message-ID: <65531D426735784F854EE658938A585303D6D2B2@MI8NYCMAIL03.Mi8.com> Hi Matthew - This is a tough kind of problem to debug through email ;) Is there any chance that the exceptions you raise cause any of your C# to be called again? If not, if there is any way you can distill your code to a relatively small example that demonstrates the problem, send it to me and I'll take a look. -Brian > -----Original Message----- > From: pythondotnet-bounces at python.org > [mailto:pythondotnet-bounces at python.org] On Behalf Of Matthew > Pontefract > Sent: Tuesday, June 06, 2006 6:08 AM > To: pythondotnet at python.org > Subject: [Python.NET] .NET 2 and hang with AcquireLock > > > > Hello > > > I have a question pertaining to running Python NET under .NET > version 2 which, admittedly, is not the version for which the > packages are built. > > > > All works just fine - I am using the PythonEngine inside a > web service, acquiring the GIL before operations, releasing > it in a 'finally' block afterwards. This is fine provided no > python exceptions are raised in the Python code. Even though > the GIL is released in the C#, a subsequent call to > AcquireLock will hang as if waiting for it to be released. No > calls to acquirelock have been made between the last call to > release the GIL and the call that hangs. > > > Has anyone else had this problem? > > > > I am using Python 2.4 > > > > Regards > > Matthew > > > > Dr Matthew Pontefract > > Credaris Portfolio Management > > ________________________________________ > > > > mp at credaris.com > > T : (44) 207 925 8365 > > F : (44) 207 925 8399 > > > > CPM Advisers Limited > > Norfolk House > > 30 Charles II Street > > London > > SW1Y 4AE > > www.credaris.com > > > > Regulated by the Financial Services Authority > > > > From MP at credaris.com Tue Jun 6 17:36:45 2006 From: MP at credaris.com (Matthew Pontefract) Date: Tue, 6 Jun 2006 16:36:45 +0100 Subject: [Python.NET] .NET 2 and hang with AcquireLock Message-ID: <8EE03F7BD203224A972E4A479E6CDE81F50851@cpm01.creditportfolio.com> Thanks for your reply Brian - I have been playing around with this a fair bit. I checked out the source code from Subversion; the revision from 2nd June built with no problems and so I now have a .NET 2 build which appears to work well from the console etc. Using this from my C# web service exhibits the same behaviour as before however! The problem is really quite tricky because in fact it is wider than I previously suspected: the web service will successfully acquire the lock once or twice in a row, but will then hang at the AcquireLock call regardless of whether a Python exception had been raised in code or not. I don't think any of the C# code would have been called again (and I kept tabs on calls to acquire and drop the lock), nor is there any re-entrant code. This prompted me to change my approach to a rather more satisfactory one anyway: I use ZSI to create a separate web service from python directly and call that web service from my C# app. I use PythonNet because I want to use business code available in .NET assemblies. Thanks to PythonNet it's been a breeze to use Python in what is otherwise a very C# environment - I'm really pleased. Even though I've changed tack, when I have time I'll get a debugger onto the PythonNet code and try and trace this further - I'll post back if I get anywhere. It would be interesting to know if it's something peculiar to me! For your information, as requested, the code where the problem occurred is as follows (it's all a touch noddy - various permutations of this were tried, so that's why the gs lock object rather bizarrely ended up static etc...): public class Reporting { private static IntPtr gs; public static void GenerateReport(String report) { if (!PythonEngine.IsInitialized) { PythonEngine.Initialize(); gs = PythonEngine.AcquireLock(); try { PythonEngine.RunSimpleString("import sys"); PythonEngine.RunSimpleString("sys.path.append('g:/pyccolo')"); PythonEngine.RunSimpleString("from report.server_init import *"); PythonEngine.RunSimpleString("print(sys.path)"); PythonEngine.RunSimpleString("o.flush()"); } finally { PythonEngine.ReleaseLock(gs); } } gs = PythonEngine.AcquireLock(); try { PythonEngine.RunSimpleString("runReport('"+report+"')"); PythonEngine.RunSimpleString("o.flush()"); } finally { PythonEngine.ReleaseLock(gs); } } } Regards Matthew -----Original Message----- From: Brian Lloyd [mailto:Brian.Lloyd at revolution.com] Sent: 06 June 2006 14:24 To: Matthew Pontefract; pythondotnet at python.org Subject: RE: [Python.NET] .NET 2 and hang with AcquireLock Hi Matthew - This is a tough kind of problem to debug through email ;) Is there any chance that the exceptions you raise cause any of your C# to be called again? If not, if there is any way you can distill your code to a relatively small example that demonstrates the problem, send it to me and I'll take a look. -Brian > -----Original Message----- > From: pythondotnet-bounces at python.org > [mailto:pythondotnet-bounces at python.org] On Behalf Of Matthew > Pontefract > Sent: Tuesday, June 06, 2006 6:08 AM > To: pythondotnet at python.org > Subject: [Python.NET] .NET 2 and hang with AcquireLock > > > > Hello > > > I have a question pertaining to running Python NET under .NET > version 2 which, admittedly, is not the version for which the > packages are built. > > > > All works just fine - I am using the PythonEngine inside a > web service, acquiring the GIL before operations, releasing > it in a 'finally' block afterwards. This is fine provided no > python exceptions are raised in the Python code. Even though > the GIL is released in the C#, a subsequent call to > AcquireLock will hang as if waiting for it to be released. No > calls to acquirelock have been made between the last call to > release the GIL and the call that hangs. > > > Has anyone else had this problem? > > > > I am using Python 2.4 > > > > Regards > > Matthew > > > > Dr Matthew Pontefract > > Credaris Portfolio Management > > ________________________________________ > > > > mp at credaris.com > > T : (44) 207 925 8365 > > F : (44) 207 925 8399 > > > > CPM Advisers Limited > > Norfolk House > > 30 Charles II Street > > London > > SW1Y 4AE > > www.credaris.com > > > > Regulated by the Financial Services Authority > > > > http://www.credaris.com/disclaimer.php From Brian.Lloyd at revolution.com Tue Jun 6 17:51:29 2006 From: Brian.Lloyd at revolution.com (Brian Lloyd) Date: Tue, 6 Jun 2006 11:51:29 -0400 Subject: [Python.NET] .NET 2 and hang with AcquireLock Message-ID: <65531D426735784F854EE658938A585303D6D6E6@MI8NYCMAIL03.Mi8.com> Thanks for the info. Looking at this, an idea came to mind that might be worth looking into: Is GenerateReport() called on a per-request basis as a web service? If so, you might try initializing the python engine once at startup rather than per-request. I'm actually not sure that reinitializing the engine in the same process will work in any reliable way (there are allegations on the python lists that this is a grey area in regard to the C python runtime). If nothing else, it could be causing two instances of Reporting to try to initialize the engine at the same time. Since they are both essentially initializing a single C runtime, I could imagine the GIL getting balled up in that case pretty easily. -Brian > -----Original Message----- > From: Matthew Pontefract [mailto:MP at credaris.com] > Sent: Tuesday, June 06, 2006 11:37 AM > To: Brian Lloyd; pythondotnet at python.org > Subject: RE: [Python.NET] .NET 2 and hang with AcquireLock > > Thanks for your reply Brian - I have been playing around with > this a fair bit. I checked out the source code from > Subversion; the revision from 2nd June built with no problems > and so I now have a .NET 2 build which appears to work well > from the console etc. > > Using this from my C# web service exhibits the same behaviour > as before however! The problem is really quite tricky because > in fact it is wider than I previously suspected: the web > service will successfully acquire the lock once or twice in a > row, but will then hang at the AcquireLock call regardless of > whether a Python exception had been raised in code or not. > > I don't think any of the C# code would have been called again > (and I kept tabs on calls to acquire and drop the lock), nor > is there any re-entrant code. > > This prompted me to change my approach to a rather more > satisfactory one > anyway: I use ZSI to create a separate web service from > python directly and call that web service from my C# app. I > use PythonNet because I want to use business code available > in .NET assemblies. Thanks to PythonNet it's been a breeze to > use Python in what is otherwise a very C# environment - I'm > really pleased. > > Even though I've changed tack, when I have time I'll get a > debugger onto the PythonNet code and try and trace this > further - I'll post back if I get anywhere. It would be > interesting to know if it's something peculiar to me! > > For your information, as requested, the code where the > problem occurred is as follows (it's all a touch noddy - > various permutations of this were tried, so that's why the gs > lock object rather bizarrely ended up static etc...): > > public class Reporting > { > private static IntPtr gs; > public static void GenerateReport(String report) > { > if (!PythonEngine.IsInitialized) > { > PythonEngine.Initialize(); > gs = PythonEngine.AcquireLock(); > try > { > > PythonEngine.RunSimpleString("import sys"); > > PythonEngine.RunSimpleString("sys.path.append('g:/pyccolo')"); > > PythonEngine.RunSimpleString("from report.server_init import *"); > > PythonEngine.RunSimpleString("print(sys.path)"); > > PythonEngine.RunSimpleString("o.flush()"); > } > finally > { > PythonEngine.ReleaseLock(gs); > } > } > > gs = PythonEngine.AcquireLock(); > try > { > > PythonEngine.RunSimpleString("runReport('"+report+"')"); > > PythonEngine.RunSimpleString("o.flush()"); > } > finally > { > PythonEngine.ReleaseLock(gs); > } > } > } > > Regards > Matthew > > -----Original Message----- > From: Brian Lloyd [mailto:Brian.Lloyd at revolution.com] > Sent: 06 June 2006 14:24 > To: Matthew Pontefract; pythondotnet at python.org > Subject: RE: [Python.NET] .NET 2 and hang with AcquireLock > > Hi Matthew - > > This is a tough kind of problem to debug through email ;) > > Is there any chance that the exceptions you raise cause any > of your C# to be called again? > > If not, if there is any way you can distill your code to a > relatively small example that demonstrates the problem, send > it to me and I'll take a look. > > -Brian > > > -----Original Message----- > > From: pythondotnet-bounces at python.org > > [mailto:pythondotnet-bounces at python.org] On Behalf Of Matthew > > Pontefract > > Sent: Tuesday, June 06, 2006 6:08 AM > > To: pythondotnet at python.org > > Subject: [Python.NET] .NET 2 and hang with AcquireLock > > > > > > > > Hello > > > > > > I have a question pertaining to running Python NET under > .NET version > > 2 which, admittedly, is not the version for which the packages are > > built. > > > > > > > > All works just fine - I am using the PythonEngine inside a web > > service, acquiring the GIL before operations, releasing it in a > > 'finally' block afterwards. This is fine provided no python > exceptions > > are raised in the Python code. Even though the GIL is > released in the > > C#, a subsequent call to AcquireLock will hang as if > waiting for it to > > be released. No calls to acquirelock have been made between > the last > > call to release the GIL and the call that hangs. > > > > > > Has anyone else had this problem? > > > > > > > > I am using Python 2.4 > > > > > > > > Regards > > > > Matthew > > > > > > > > Dr Matthew Pontefract > > > > Credaris Portfolio Management > > > > ________________________________________ > > > > > > > > mp at credaris.com > > > > T : (44) 207 925 8365 > > > > F : (44) 207 925 8399 > > > > > > > > CPM Advisers Limited > > > > Norfolk House > > > > 30 Charles II Street > > > > London > > > > SW1Y 4AE > > > > www.credaris.com > > > > > > > > Regulated by the Financial Services Authority > > > > > > > > > > > http://www.credaris.com/disclaimer.php > > > From MP at credaris.com Tue Jun 6 18:04:16 2006 From: MP at credaris.com (Matthew Pontefract) Date: Tue, 6 Jun 2006 17:04:16 +0100 Subject: [Python.NET] .NET 2 and hang with AcquireLock Message-ID: <8EE03F7BD203224A972E4A479E6CDE81F50852@cpm01.creditportfolio.com> Hi Brian GenerateReport() is indeed called on a per-request basis but the python engine is initialized only once: on subsequent calls PythonEngine.IsInitialised returns true and the initialization code (all of which is in the body of the if clause) is skipped (I've confirmed this by stepping over the code). Another thing that I tried as I was running out of ideas was to ensure that the GenerateReport method was never run in parallel by locking the entire code block, thus guaranteeing that there would only be one attempt to acquire the GIL at any time (not that my testing ever resulted in simultaneous calls to the function). Needless to say, this did nothing to help matters! Regards Matthew -----Original Message----- From: Brian Lloyd [mailto:Brian.Lloyd at revolution.com] Sent: 06 June 2006 16:51 To: Matthew Pontefract; pythondotnet at python.org Subject: RE: [Python.NET] .NET 2 and hang with AcquireLock Thanks for the info. Looking at this, an idea came to mind that might be worth looking into: Is GenerateReport() called on a per-request basis as a web service? If so, you might try initializing the python engine once at startup rather than per-request. I'm actually not sure that reinitializing the engine in the same process will work in any reliable way (there are allegations on the python lists that this is a grey area in regard to the C python runtime). If nothing else, it could be causing two instances of Reporting to try to initialize the engine at the same time. Since they are both essentially initializing a single C runtime, I could imagine the GIL getting balled up in that case pretty easily. -Brian > -----Original Message----- > From: Matthew Pontefract [mailto:MP at credaris.com] > Sent: Tuesday, June 06, 2006 11:37 AM > To: Brian Lloyd; pythondotnet at python.org > Subject: RE: [Python.NET] .NET 2 and hang with AcquireLock > > Thanks for your reply Brian - I have been playing around with > this a fair bit. I checked out the source code from > Subversion; the revision from 2nd June built with no problems > and so I now have a .NET 2 build which appears to work well > from the console etc. > > Using this from my C# web service exhibits the same behaviour > as before however! The problem is really quite tricky because > in fact it is wider than I previously suspected: the web > service will successfully acquire the lock once or twice in a > row, but will then hang at the AcquireLock call regardless of > whether a Python exception had been raised in code or not. > > I don't think any of the C# code would have been called again > (and I kept tabs on calls to acquire and drop the lock), nor > is there any re-entrant code. > > This prompted me to change my approach to a rather more > satisfactory one > anyway: I use ZSI to create a separate web service from > python directly and call that web service from my C# app. I > use PythonNet because I want to use business code available > in .NET assemblies. Thanks to PythonNet it's been a breeze to > use Python in what is otherwise a very C# environment - I'm > really pleased. > > Even though I've changed tack, when I have time I'll get a > debugger onto the PythonNet code and try and trace this > further - I'll post back if I get anywhere. It would be > interesting to know if it's something peculiar to me! > > For your information, as requested, the code where the > problem occurred is as follows (it's all a touch noddy - > various permutations of this were tried, so that's why the gs > lock object rather bizarrely ended up static etc...): > > public class Reporting > { > private static IntPtr gs; > public static void GenerateReport(String report) > { > if (!PythonEngine.IsInitialized) > { > PythonEngine.Initialize(); > gs = PythonEngine.AcquireLock(); > try > { > > PythonEngine.RunSimpleString("import sys"); > > PythonEngine.RunSimpleString("sys.path.append('g:/pyccolo')"); > > PythonEngine.RunSimpleString("from report.server_init import *"); > > PythonEngine.RunSimpleString("print(sys.path)"); > > PythonEngine.RunSimpleString("o.flush()"); > } > finally > { > PythonEngine.ReleaseLock(gs); > } > } > > gs = PythonEngine.AcquireLock(); > try > { > > PythonEngine.RunSimpleString("runReport('"+report+"')"); > > PythonEngine.RunSimpleString("o.flush()"); > } > finally > { > PythonEngine.ReleaseLock(gs); > } > } > } > > Regards > Matthew > > -----Original Message----- > From: Brian Lloyd [mailto:Brian.Lloyd at revolution.com] > Sent: 06 June 2006 14:24 > To: Matthew Pontefract; pythondotnet at python.org > Subject: RE: [Python.NET] .NET 2 and hang with AcquireLock > > Hi Matthew - > > This is a tough kind of problem to debug through email ;) > > Is there any chance that the exceptions you raise cause any > of your C# to be called again? > > If not, if there is any way you can distill your code to a > relatively small example that demonstrates the problem, send > it to me and I'll take a look. > > -Brian > > > -----Original Message----- > > From: pythondotnet-bounces at python.org > > [mailto:pythondotnet-bounces at python.org] On Behalf Of Matthew > > Pontefract > > Sent: Tuesday, June 06, 2006 6:08 AM > > To: pythondotnet at python.org > > Subject: [Python.NET] .NET 2 and hang with AcquireLock > > > > > > > > Hello > > > > > > I have a question pertaining to running Python NET under > .NET version > > 2 which, admittedly, is not the version for which the packages are > > built. > > > > > > > > All works just fine - I am using the PythonEngine inside a web > > service, acquiring the GIL before operations, releasing it in a > > 'finally' block afterwards. This is fine provided no python > exceptions > > are raised in the Python code. Even though the GIL is > released in the > > C#, a subsequent call to AcquireLock will hang as if > waiting for it to > > be released. No calls to acquirelock have been made between > the last > > call to release the GIL and the call that hangs. > > > > > > Has anyone else had this problem? > > > > > > > > I am using Python 2.4 > > > > > > > > Regards > > > > Matthew > > > > > > > > Dr Matthew Pontefract > > > > Credaris Portfolio Management > > > > ________________________________________ > > > > > > > > mp at credaris.com > > > > T : (44) 207 925 8365 > > > > F : (44) 207 925 8399 > > > > > > > > CPM Advisers Limited > > > > Norfolk House > > > > 30 Charles II Street > > > > London > > > > SW1Y 4AE > > > > www.credaris.com > > > > > > > > Regulated by the Financial Services Authority > > > > > > > > > > > http://www.credaris.com/disclaimer.php > > > http://www.credaris.com/disclaimer.php From shivanan at statictype.org Fri Jun 9 05:27:05 2006 From: shivanan at statictype.org (Haran Shivanan) Date: Fri, 09 Jun 2006 08:57:05 +0530 Subject: [Python.NET] exposing modules Message-ID: <4488EA89.5010106@statictype.org> Hi, I'm trying to embed the python interpreter in my .NET-based program. The basic stuff is working fine. But now, I want to expose some of my program's internal data to the scripts. (ie, not just functions that live in an assembly, but access to my live program's state) For example, if I have a WinForms application, I want to be able to access a textbox's current text from python. Ideally, I should be able to do something like this from a script: import MyApp s = MyApp.GetText() Is there any way to do this in Python.NET? And if not, can someone provide me with some pointers on how to go about adding the functionality to the Python.NET code? (I believe we have to use issue a call to Py_InitModule or something, right?) Thanks, Haran From Brian.Lloyd at revolution.com Fri Jun 9 15:54:12 2006 From: Brian.Lloyd at revolution.com (Brian Lloyd) Date: Fri, 9 Jun 2006 09:54:12 -0400 Subject: [Python.NET] exposing modules Message-ID: <65531D426735784F854EE658938A585303F02D3C@MI8NYCMAIL03.Mi8.com> Haran - you can't expose a 'module' (in the Python sense), but you can easily do what you trying to do. The usual pattern for this would be stow away a reference to your application object in a static where the Python code can then get it. Assuming you have an assembly 'my.app', this would look like: namespace my.app { public class MyApp { public static MyApp theapp; public MyApp() { // do initialization theapp = this; } } } Now from Python you can do the following: from my.app import MyApp app = MyApp.theapp hope this helps, -Brian > -----Original Message----- > From: pythondotnet-bounces at python.org > [mailto:pythondotnet-bounces at python.org] On Behalf Of Haran Shivanan > Sent: Thursday, June 08, 2006 11:27 PM > To: pythondotnet at python.org > Subject: [Python.NET] exposing modules > > Hi, > > I'm trying to embed the python interpreter in my .NET-based program. > The basic stuff is working fine. > But now, I want to expose some of my program's internal data > to the scripts. > (ie, not just functions that live in an assembly, but access > to my live program's state) For example, if I have a WinForms > application, I want to be able to access a textbox's current > text from python. > Ideally, I should be able to do something like this from a script: > import MyApp > s = MyApp.GetText() > > Is there any way to do this in Python.NET? > And if not, can someone provide me with some pointers on how > to go about adding the functionality to the Python.NET code? > (I believe we have to use issue a call to Py_InitModule or something, > right?) > > Thanks, > Haran > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > > From shivanan at statictype.org Fri Jun 9 20:22:48 2006 From: shivanan at statictype.org (Haran Shivanan) Date: Fri, 09 Jun 2006 23:52:48 +0530 Subject: [Python.NET] exposing modules In-Reply-To: <65531D426735784F854EE658938A585303F02D3C@MI8NYCMAIL03.Mi8.com> References: <65531D426735784F854EE658938A585303F02D3C@MI8NYCMAIL03.Mi8.com> Message-ID: <4489BC78.1010109@statictype.org> Brian Lloyd wrote: >Haran - you can't expose a 'module' (in the Python sense), but >you can easily do what you trying to do. > > Awesome. That worked. Didn't think it would be that easy! Thanks a lot. Haran From Radhika.Srivatsa at ngc.com Tue Jun 13 22:47:56 2006 From: Radhika.Srivatsa at ngc.com (Srivatsa, Radhika) Date: Tue, 13 Jun 2006 13:47:56 -0700 Subject: [Python.NET] exposing modules In-Reply-To: <4488EA89.5010106@statictype.org> Message-ID: <2E31CB5D3E672047A7C4D44CB56010C24D3EAD@XMBCAK04> Hi, I am trying to achieve the first step still - of emedding the python interpreter within my .NET application and am kind of stuck there. Here's what I did: 1) Added "Python.Runtime.dll" to the build (of .NET project). 2) Added the following line in the constructor: PythonEngine.Initialize(); This gives me the following errors: error C2065: 'PythonEngine' : undeclared identifier error C2228: left of '.Initialize' must have class/struct/union type type is ''unknown-type'' What other step have I missed ? Thanks --Radhika Radhika Srivatsa UMS Software Development Voice: (858)618-2235 >-----Original Message----- >From: pythondotnet-bounces at python.org >[mailto:pythondotnet-bounces at python.org] On Behalf Of Haran Shivanan >Sent: Thursday, June 08, 2006 8:27 PM >To: pythondotnet at python.org >Subject: [Python.NET] exposing modules > >Hi, > >I'm trying to embed the python interpreter in my .NET-based program. >The basic stuff is working fine. >But now, I want to expose some of my program's internal data >to the scripts. >(ie, not just functions that live in an assembly, but access >to my live program's state) For example, if I have a WinForms >application, I want to be able to access a textbox's current >text from python. >Ideally, I should be able to do something like this from a script: >import MyApp >s = MyApp.GetText() > >Is there any way to do this in Python.NET? >And if not, can someone provide me with some pointers on how >to go about adding the functionality to the Python.NET code? >(I believe we have to use issue a call to Py_InitModule or something, >right?) > >Thanks, >Haran >_________________________________________________ >Python.NET mailing list - PythonDotNet at python.org >http://mail.python.org/mailman/listinfo/pythondotnet > From MP at credaris.com Wed Jun 14 09:24:34 2006 From: MP at credaris.com (Matthew Pontefract) Date: Wed, 14 Jun 2006 08:24:34 +0100 Subject: [Python.NET] exposing modules Message-ID: <8EE03F7BD203224A972E4A479E6CDE81F50859@cpm01.creditportfolio.com> Hi Haran It sounds almost as though the Python.Runtime.dll, though added to your project, is not listed as a reference for the code you're compiling. In Visual Studio 2005 (the only one of which I have experience) you'd click References and add a new one (navigating to the dll). If using nant, the element needs a child element containing an . Once done, and assuming you have not omitted the using statement in your code (and not mis-spelled the package name) I would hope your code would compile. I appologise if I'm merely stating the obvious here - your email didn't have a huge amount to go on so I'm just running down the list of things I personally would check first! If you still have trouble, let us know how you are building your code etc. and I'll try and help further :) Kind regards Matthew -----Original Message----- From: pythondotnet-bounces at python.org [mailto:pythondotnet-bounces at python.org] On Behalf Of Srivatsa, Radhika Sent: 13 June 2006 21:48 To: Haran Shivanan; pythondotnet at python.org Subject: Re: [Python.NET] exposing modules Hi, I am trying to achieve the first step still - of emedding the python interpreter within my .NET application and am kind of stuck there. Here's what I did: 1) Added "Python.Runtime.dll" to the build (of .NET project). 2) Added the following line in the constructor: PythonEngine.Initialize(); This gives me the following errors: error C2065: 'PythonEngine' : undeclared identifier error C2228: left of '.Initialize' must have class/struct/union type type is ''unknown-type'' What other step have I missed ? Thanks --Radhika Radhika Srivatsa UMS Software Development Voice: (858)618-2235 >-----Original Message----- >From: pythondotnet-bounces at python.org >[mailto:pythondotnet-bounces at python.org] On Behalf Of Haran Shivanan >Sent: Thursday, June 08, 2006 8:27 PM >To: pythondotnet at python.org >Subject: [Python.NET] exposing modules > >Hi, > >I'm trying to embed the python interpreter in my .NET-based program. >The basic stuff is working fine. >But now, I want to expose some of my program's internal data >to the scripts. >(ie, not just functions that live in an assembly, but access >to my live program's state) For example, if I have a WinForms >application, I want to be able to access a textbox's current >text from python. >Ideally, I should be able to do something like this from a script: >import MyApp >s = MyApp.GetText() > >Is there any way to do this in Python.NET? >And if not, can someone provide me with some pointers on how >to go about adding the functionality to the Python.NET code? >(I believe we have to use issue a call to Py_InitModule or something, >right?) > >Thanks, >Haran >_________________________________________________ >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 From Brian.Lloyd at revolution.com Wed Jun 14 16:00:12 2006 From: Brian.Lloyd at revolution.com (Brian Lloyd) Date: Wed, 14 Jun 2006 10:00:12 -0400 Subject: [Python.NET] exposing modules Message-ID: <65531D426735784F854EE658938A585304068DFD@MI8NYCMAIL03.Mi8.com> I was going to say that the error message sounds like the code is missing a 'using Python.Runtime'... -Brian > -----Original Message----- > From: pythondotnet-bounces at python.org > [mailto:pythondotnet-bounces at python.org] On Behalf Of Matthew > Pontefract > Sent: Wednesday, June 14, 2006 3:25 AM > To: Srivatsa, Radhika; Haran Shivanan; pythondotnet at python.org > Subject: Re: [Python.NET] exposing modules > > Hi Haran > > It sounds almost as though the Python.Runtime.dll, though > added to your project, is not listed as a reference for the > code you're compiling. In Visual Studio 2005 (the only one of > which I have experience) you'd click References and add a new > one (navigating to the dll). If using nant, the element > needs a child element containing an name="Python.Runtime.dll"/>. > > Once done, and assuming you have not omitted the using > statement in your code (and not mis-spelled the package name) > I would hope your code would compile. > > I appologise if I'm merely stating the obvious here - your > email didn't have a huge amount to go on so I'm just running > down the list of things I personally would check first! If > you still have trouble, let us know how you are building your > code etc. and I'll try and help further :) > > Kind regards > Matthew > > -----Original Message----- > From: pythondotnet-bounces at python.org > [mailto:pythondotnet-bounces at python.org] On Behalf Of > Srivatsa, Radhika > Sent: 13 June 2006 21:48 > To: Haran Shivanan; pythondotnet at python.org > Subject: Re: [Python.NET] exposing modules > > Hi, > > I am trying to achieve the first step still - of emedding the > python interpreter within my .NET application and am kind of > stuck there. > > Here's what I did: > > 1) Added "Python.Runtime.dll" to the build (of .NET project). > > 2) Added the following line in the constructor: > PythonEngine.Initialize(); > > This gives me the following errors: > error C2065: 'PythonEngine' : undeclared identifier error > C2228: left of '.Initialize' must have class/struct/union type > type is ''unknown-type'' > > What other step have I missed ? > > Thanks > > --Radhika > > Radhika Srivatsa > UMS Software Development > Voice: (858)618-2235 > > > >-----Original Message----- > >From: pythondotnet-bounces at python.org > >[mailto:pythondotnet-bounces at python.org] On Behalf Of Haran Shivanan > >Sent: Thursday, June 08, 2006 8:27 PM > >To: pythondotnet at python.org > >Subject: [Python.NET] exposing modules > > > >Hi, > > > >I'm trying to embed the python interpreter in my .NET-based program. > >The basic stuff is working fine. > >But now, I want to expose some of my program's internal data to the > >scripts. > >(ie, not just functions that live in an assembly, but access > to my live > >program's state) For example, if I have a WinForms > application, I want > >to be able to access a textbox's current text from python. > >Ideally, I should be able to do something like this from a script: > >import MyApp > >s = MyApp.GetText() > > > >Is there any way to do this in Python.NET? > >And if not, can someone provide me with some pointers on how to go > >about adding the functionality to the Python.NET code? > >(I believe we have to use issue a call to Py_InitModule or something, > >right?) > > > >Thanks, > >Haran > >_________________________________________________ > >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 > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > > From MP at credaris.com Thu Jun 15 12:12:05 2006 From: MP at credaris.com (Matthew Pontefract) Date: Thu, 15 Jun 2006 11:12:05 +0100 Subject: [Python.NET] exposing modules Message-ID: <8EE03F7BD203224A972E4A479E6CDE81F5085A@cpm01.creditportfolio.com> Hi Srivatsa I am working in a group building a C# application and have been bringing my Python background to the project so I have worked with both IronPython and, most recently, PythonNet. Python .NET uses the normal CPython and provides something of an interface layer that allows your Python code to call, use and interact with .NET assemblies. As you have found, you can embed it in .NET code and call from .NET into it. It is a bridge solution that provides a path between CPython and .NET, but the Python code is NOT compiled to MSIL, so your python classes will not be accessible to .NET code directly. IronPython is a first class .NET language. Python code is compiled to MSIL and executed in the .NET machine. Python classes can interact much more closely with .NET code and it is possible I believe (though I've not done this) to create .NET assemblies and uses classes coded in Python used by any other .NET application. It's Python for .NET in the proper sense. It's easy to embed and put a Python console into your .NET application. The downside of IP is that it is a relatively young product and you can't expect just any Python library to run in IronPython because of differences in provision of a number of core packages, including OS and a number of others. It is fantastic for adding scripting to a .NET application, but it is less useful (at the moment - this will change I have no doubt) for running scripts that leverage many of the more complex Python packages out there. On the flip side, being a .NET language, you can debug into your IronPython run code using dev studio. PyUnit may or may not work on IronPython (probably will, actually, but I've not tried). PythonNet is ideal for me because I don't need my C# code to call Python objects - but I need the Python to work with my .NET assemblies and I want to use a number of CPython packages. PyUnit is the Python unit testing framework. As I said, I'm not sure how well it fares under IronPython, but it is simple enough to use that it's worth a try; it'll only take up half an hour or so I'm sure. If you wish simply to write testing of your .NET code in Python, I would have thought that PythonNet will do the trick just fine. You needn't call it from within a .NET class either, unless that is a necessity for some reason. You can just run it from the command line. By installing PythonNET into your current installation you can run normal python from the command line, import clr, and then work with .NET objects. By adding the path to your .NET dlls you can access all your code and, of course, run tests on it. If you wish only to run unit tests, this is probably the approach that I would take. You can use PyDev on Eclipse etc to debug through code if needed. I have recently built a version from Brian's subversion sources to run under .NET 2 and installed it such that I can use it from CPython. I can help with this if you'd like to go down this route in .NET 2. If you're using .NET 1 then the binaries are available all ready packaged and you shouldn't need to do any compilation. Regards Matthew -----Original Message----- From: Srivatsa, Radhika [mailto:Radhika.Srivatsa at ngc.com] Sent: 14 June 2006 14:47 To: Matthew Pontefract Subject: RE: [Python.NET] exposing modules Thank you very much for your inputs. After reading more and more about Python and its different flavors, I think I have a more fundamental question. Here's what I am trying to achieve and could you pls let me know what is the best tool I can use for doing this: Currently, I have a .NET project (solution) application running on Windows. This application is written in VC++ and we are now using Visual Basic to unit test the code and my goal is to replace VB by Python such that I can write Python scripts to achieve the Unit Testing. I know Python will help me eliminate the usage of VB, right ? Now that we have identified Python, what kind do I use - PyUnit, Python for .NET or IronPython ? It is here that I am sort of confused. I'd appreciate your inputs in helping me identify what kind of Python I'd have to use to achieve my goal. --Radhika Radhika Srivatsa UMS Software Development Voice: (858)618-2235 >-----Original Message----- >From: pythondotnet-bounces at python.org >[mailto:pythondotnet-bounces at python.org] On Behalf Of Matthew >Pontefract >Sent: Wednesday, June 14, 2006 12:25 AM >To: Srivatsa, Radhika; Haran Shivanan; pythondotnet at python.org >Subject: Re: [Python.NET] exposing modules > >Hi Haran > >It sounds almost as though the Python.Runtime.dll, though >added to your project, is not listed as a reference for the >code you're compiling. In Visual Studio 2005 (the only one of >which I have experience) you'd click References and add a new >one (navigating to the dll). If using nant, the element >needs a child element containing an name="Python.Runtime.dll"/>. > >Once done, and assuming you have not omitted the using >statement in your code (and not mis-spelled the package name) >I would hope your code would compile. > >I appologise if I'm merely stating the obvious here - your >email didn't have a huge amount to go on so I'm just running >down the list of things I personally would check first! If you >still have trouble, let us know how you are building your code >etc. and I'll try and help further :) > >Kind regards >Matthew > >-----Original Message----- >From: pythondotnet-bounces at python.org >[mailto:pythondotnet-bounces at python.org] On Behalf Of Srivatsa, Radhika >Sent: 13 June 2006 21:48 >To: Haran Shivanan; pythondotnet at python.org >Subject: Re: [Python.NET] exposing modules > >Hi, > >I am trying to achieve the first step still - of emedding the >python interpreter within my .NET application and am kind of >stuck there. > >Here's what I did: > >1) Added "Python.Runtime.dll" to the build (of .NET project). > >2) Added the following line in the constructor: > PythonEngine.Initialize(); > >This gives me the following errors: >error C2065: 'PythonEngine' : undeclared identifier error >C2228: left of '.Initialize' must have class/struct/union type > type is ''unknown-type'' > >What other step have I missed ? > >Thanks > >--Radhika > >Radhika Srivatsa >UMS Software Development >Voice: (858)618-2235 > > >>-----Original Message----- >>From: pythondotnet-bounces at python.org >>[mailto:pythondotnet-bounces at python.org] On Behalf Of Haran Shivanan >>Sent: Thursday, June 08, 2006 8:27 PM >>To: pythondotnet at python.org >>Subject: [Python.NET] exposing modules >> >>Hi, >> >>I'm trying to embed the python interpreter in my .NET-based program. >>The basic stuff is working fine. >>But now, I want to expose some of my program's internal data to the >>scripts. >>(ie, not just functions that live in an assembly, but access >to my live >>program's state) For example, if I have a WinForms >application, I want >>to be able to access a textbox's current text from python. >>Ideally, I should be able to do something like this from a script: >>import MyApp >>s = MyApp.GetText() >> >>Is there any way to do this in Python.NET? >>And if not, can someone provide me with some pointers on how to go >>about adding the functionality to the Python.NET code? >>(I believe we have to use issue a call to Py_InitModule or something, >>right?) >> >>Thanks, >>Haran >>_________________________________________________ >>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 >_________________________________________________ >Python.NET mailing list - PythonDotNet at python.org >http://mail.python.org/mailman/listinfo/pythondotnet > From shivanan at statictype.org Thu Jun 15 15:05:49 2006 From: shivanan at statictype.org (Haran Shivanan) Date: Thu, 15 Jun 2006 18:35:49 +0530 Subject: [Python.NET] exposing modules In-Reply-To: <8EE03F7BD203224A972E4A479E6CDE81F50859@cpm01.creditportfolio.com> References: <8EE03F7BD203224A972E4A479E6CDE81F50859@cpm01.creditportfolio.com> Message-ID: <44915B2D.6040307@statictype.org> Hi , All (Minor point, but I'm not the author of that mail. I think Srivatsa asked the question) Anyway, I think you need to add a "using Python.Runtime" clause to the top of the file before this will work. Thanks, Haran Matthew Pontefract wrote: >Hi Haran > >It sounds almost as though the Python.Runtime.dll, though added to your >project, is not listed as a reference for the code you're compiling. In >Visual Studio 2005 (the only one of which I have experience) you'd click >References and add a new one (navigating to the dll). If using nant, the > element needs a child element containing an name="Python.Runtime.dll"/>. > >Once done, and assuming you have not omitted the using statement in your >code (and not mis-spelled the package name) I would hope your code would >compile. > >I appologise if I'm merely stating the obvious here - your email didn't >have a huge amount to go on so I'm just running down the list of things >I personally would check first! If you still have trouble, let us know >how you are building your code etc. and I'll try and help further :) > >Kind regards >Matthew > >-----Original Message----- >From: pythondotnet-bounces at python.org >[mailto:pythondotnet-bounces at python.org] On Behalf Of Srivatsa, Radhika >Sent: 13 June 2006 21:48 >To: Haran Shivanan; pythondotnet at python.org >Subject: Re: [Python.NET] exposing modules > >Hi, > >I am trying to achieve the first step still - of emedding the python >interpreter within my .NET application and am kind of stuck there. > >Here's what I did: > >1) Added "Python.Runtime.dll" to the build (of .NET project). > >2) Added the following line in the constructor: > PythonEngine.Initialize(); > >This gives me the following errors: >error C2065: 'PythonEngine' : undeclared identifier >error C2228: left of '.Initialize' must have class/struct/union type > type is ''unknown-type'' > >What other step have I missed ? > >Thanks > >--Radhika > >Radhika Srivatsa >UMS Software Development >Voice: (858)618-2235 > > > > >>-----Original Message----- >>From: pythondotnet-bounces at python.org >>[mailto:pythondotnet-bounces at python.org] On Behalf Of Haran Shivanan >>Sent: Thursday, June 08, 2006 8:27 PM >>To: pythondotnet at python.org >>Subject: [Python.NET] exposing modules >> >>Hi, >> >>I'm trying to embed the python interpreter in my .NET-based program. >>The basic stuff is working fine. >>But now, I want to expose some of my program's internal data >>to the scripts. >>(ie, not just functions that live in an assembly, but access >>to my live program's state) For example, if I have a WinForms >>application, I want to be able to access a textbox's current >>text from python. >>Ideally, I should be able to do something like this from a script: >>import MyApp >>s = MyApp.GetText() >> >>Is there any way to do this in Python.NET? >>And if not, can someone provide me with some pointers on how >>to go about adding the functionality to the Python.NET code? >>(I believe we have to use issue a call to Py_InitModule or something, >>right?) >> >>Thanks, >>Haran >>_________________________________________________ >>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 > > From shivanan at statictype.org Thu Jun 15 15:21:13 2006 From: shivanan at statictype.org (Haran Shivanan) Date: Thu, 15 Jun 2006 18:51:13 +0530 Subject: [Python.NET] exposing modules In-Reply-To: <44915B2D.6040307@statictype.org> References: <8EE03F7BD203224A972E4A479E6CDE81F50859@cpm01.creditportfolio.com> <44915B2D.6040307@statictype.org> Message-ID: <44915EC9.5060101@statictype.org> Haran Shivanan wrote: >Hi , All > >(Minor point, but I'm not the author of that mail. I think Srivatsa >asked the question) >Anyway, I think you need to add a "using Python.Runtime" clause to the >top of the file before this will work. > > Nevermind. The question was already answered. Sorry for the spam From bruce_dodson at hotmail.com Fri Jun 16 22:06:41 2006 From: bruce_dodson at hotmail.com (Bruce Dodson) Date: Fri, 16 Jun 2006 17:06:41 -0300 Subject: [Python.NET] Python.NET 1.0 Final Message-ID: In the change log in SVN I see that there was a 1.0 final release, with the new import semantics back-ported, but still using .NET 1.1 in contrast to the more recent work Brian has been doing. However, I don't see the updates to the documentation in the 1.0 branch, and also I get an "unreachable code" warning when I try to compile it, so I'm not confident that it is the old branch is complete and tested. Is there a pre-built, tested 1.0 release version available somewhere? Thanks, Bruce ps. Unreachable code is after the first return in arrayobject.cs, line 44: return CLRObject.GetInstHandle(result, tp); string message = "cannot instantiate array wrapper"; return Exceptions.RaiseTypeError(message); Could be due to a merge that went awry? From Brian.Lloyd at revolution.com Fri Jun 16 22:20:51 2006 From: Brian.Lloyd at revolution.com (Brian Lloyd) Date: Fri, 16 Jun 2006 16:20:51 -0400 Subject: [Python.NET] Python.NET 1.0 Final Message-ID: <65531D426735784F854EE658938A585304193B7D@MI8NYCMAIL03.Mi8.com> Be careful of what you read in svn ;) That's where the release notes etc. that *will be* 1.0 are being worked on, but there hasn't been a 1.0 yet (that pesky day-job has been busy lately). FWIW - I'll clean up the warning, but otherwise the 1.0 branch should be stable. There are a number of things cooking in the 2.x branch that will need to be back-merged before 1.x (things like __overloads__, IP 'clr' module compatibility, etc.), and I plan to do that as a single effort rather than torture myself with a bunch of mini-merges ;) -Brian > -----Original Message----- > From: pythondotnet-bounces at python.org > [mailto:pythondotnet-bounces at python.org] On Behalf Of Bruce Dodson > Sent: Friday, June 16, 2006 4:07 PM > To: pythondotnet at python.org > Subject: [Python.NET] Python.NET 1.0 Final > > In the change log in SVN I see that there was a 1.0 final > release, with the new import semantics back-ported, but still > using .NET 1.1 in contrast to the more recent work Brian has > been doing. > > However, I don't see the updates to the documentation in the > 1.0 branch, and also I get an "unreachable code" warning when > I try to compile it, so I'm not confident that it is the old > branch is complete and tested. Is there a pre-built, tested > 1.0 release version available somewhere? > > Thanks, > Bruce > > ps. Unreachable code is after the first return in > arrayobject.cs, line 44: > > return CLRObject.GetInstHandle(result, tp); > string message = "cannot instantiate array wrapper"; > return Exceptions.RaiseTypeError(message); > > > Could be due to a merge that went awry? > > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > > From Radhika.Srivatsa at ngc.com Fri Jun 23 00:08:50 2006 From: Radhika.Srivatsa at ngc.com (Srivatsa, Radhika) Date: Thu, 22 Jun 2006 15:08:50 -0700 Subject: [Python.NET] Class Member completion In-Reply-To: <65531D426735784F854EE658938A585304193B7D@MI8NYCMAIL03.Mi8.com> Message-ID: <2E31CB5D3E672047A7C4D44CB56010C2654C9D@XMBCAK04> Like in C++, can we have the members of a class to be completed for us in the case of Python - like for example, if a class 'TestClass' has been defined with two methods "test1' and "test2" and when I enter "TestClass.", I'd like to see the possible methods/member variables that can be used - something like file-name completion (with Tab). Is this possible for Python classes like C++ classes ? Thanks --Radhika Radhika Srivatsa UMS Software Development Voice: (858)618-2235 From MP at credaris.com Fri Jun 23 10:07:51 2006 From: MP at credaris.com (Matthew Pontefract) Date: Fri, 23 Jun 2006 09:07:51 +0100 Subject: [Python.NET] Class Member completion Message-ID: <8EE03F7BD203224A972E4A479E6CDE81F5085D@cpm01.creditportfolio.com> This sort of code-completion/intellisense behaviour is not a feature of the language, of course, but a feature of the IDE that you choose to use. However, the degree of help that can be provided is determined to some extent by the features of the particular language being programmed. There are excellent C/C++ IDEs that do all of this, as you know, as there are for Java (IDEA, Eclipse etc), and these strongly typed and structured languages make it easy to write very helpful IDEs. I have found that The PyDev Extensions plug-in for Eclipse (http://www.fabioz.com/pydev/) to be pretty good in this respect. It is harder, sometimes, for an IDE to provide suggestions in a dynamic language, but there is still a great deal that it can do, and Pydev Extensions do the job pretty well. I know that there are many other IDEs for Python out there, and all can be used with PythonNet, especially if you import clr into the CPython-run application. That said, the specific example you quote is not always easy to do and so PyDev doesn't really help. Because Python is a dynamic duck-typed language it is not easy for the IDE to know what class is being dealt with. Say you pass parameter X to a function. You then type X. - *you* may know that X is class TestClass, but the IDE has no way of determining that: it could be an integer, class FooBar or a list... until runtime, the system can't be sure except for variables that have been explicitly initialized within scope at which point PyDev gives you all the help you need. Matthew -----Original Message----- From: pythondotnet-bounces+mp=credaris.com at python.org [mailto:pythondotnet-bounces+mp=credaris.com at python.org] On Behalf Of Srivatsa, Radhika Sent: 22 June 2006 23:09 To: Brian Lloyd; Bruce Dodson; pythondotnet at python.org Subject: [Python.NET] Class Member completion Like in C++, can we have the members of a class to be completed for us in the case of Python - like for example, if a class 'TestClass' has been defined with two methods "test1' and "test2" and when I enter "TestClass.", I'd like to see the possible methods/member variables that can be used - something like file-name completion (with Tab). Is this possible for Python classes like C++ classes ? Thanks --Radhika Radhika Srivatsa UMS Software Development Voice: (858)618-2235 _________________________________________________ Python.NET mailing list - PythonDotNet at python.org http://mail.python.org/mailman/listinfo/pythondotnet From bruce_dodson at hotmail.com Tue Jun 27 17:27:55 2006 From: bruce_dodson at hotmail.com (Bruce Dodson) Date: Tue, 27 Jun 2006 12:27:55 -0300 Subject: [Python.NET] Python.NET 1.0 Final References: <65531D426735784F854EE658938A585304193B7D@MI8NYCMAIL03.Mi8.com> Message-ID: Ah, I see that the IP "clr" module isn't in that branch yet (I thought that was what landed at SVN revision 21), but that after you import the capital-CLR module, the .NET assemblies now appear as top-level names (in addition to appearing under CLR). Okay, good start. "Brian Lloyd" wrote in message news:65531D426735784F854EE658938A585304193B7D at MI8NYCMAIL03.Mi8.com... > Be careful of what you read in svn ;) That's where the release notes > etc. that *will be* 1.0 are being worked on, but there hasn't been a > 1.0 yet (that pesky day-job has been busy lately). > > FWIW - I'll clean up the warning, but otherwise the 1.0 branch > should be stable. There are a number of things cooking in the 2.x > branch that will need to be back-merged before 1.x (things like > __overloads__, IP 'clr' module compatibility, etc.), and I plan > to do that as a single effort rather than torture myself with a > bunch of mini-merges ;) > > -Brian > > >> -----Original Message----- >> From: pythondotnet-bounces at python.org >> [mailto:pythondotnet-bounces at python.org] On >> Behalf Of Bruce Dodson >> Sent: Friday, June 16, 2006 4:07 PM >> To: pythondotnet at python.org >> Subject: [Python.NET] Python.NET 1.0 Final >> >> In the change log in SVN I see that there was a 1.0 final >> release, with the new import semantics back-ported, but still >> using .NET 1.1 in contrast to the more recent work Brian has >> been doing. >> >> However, I don't see the updates to the documentation in the >> 1.0 branch, and also I get an "unreachable code" warning when >> I try to compile it, so I'm not confident that it is the old >> branch is complete and tested. Is there a pre-built, tested >> 1.0 release version available somewhere? >> >> Thanks, >> Bruce >> >> ps. Unreachable code is after the first return in >> arrayobject.cs, line 44: >> >> return CLRObject.GetInstHandle(result, tp); >> string message = "cannot instantiate array wrapper"; >> return Exceptions.RaiseTypeError(message); >> >> >> Could be due to a merge that went awry? >> >> >> >> _________________________________________________ >> 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 >