From barton at BCDesignsWell.com Mon Jul 5 22:04:16 2010 From: barton at BCDesignsWell.com (Barton) Date: Mon, 05 Jul 2010 13:04:16 -0700 Subject: [Python.NET] Problem debugging to python.runtime.dll In-Reply-To: <87fx1cll9i.fsf@rhodesmill.org> References: <87fx1cll9i.fsf@rhodesmill.org> Message-ID: <4C323AC0.7010509@BCDesignsWell.com> > Vishal.Parikh wrote: >>/ />>/ We are actually using Python.Net with python 2.5 and I wanted to learn />>/ the internal architecture of the Python.Runtime.Dll. I have tried />>/ debugging the dll by attaching the process to python.exe but doesn't hit />>/ any break point. I don't know much about the compiler design and how it />>/ works internal but all I want is I should be able to debug how my C# />>/ instruction is getting executed using python.runtime.dll />>/ / >/ /In the Debug Tab of the Properties dialog for your C# project choose "Start >/ /external program" for the Start Action and select the normal CPython > executable - python.exe. In the "Command line arguments" put the full path > of the python script which calls the C# function you want to debug. If you > debug the project now it should run the python script and you should drop in > to the c# debugger at the breakpoint you set in the function called by the > Python script. > > HTH, > Dave It's been pretty quiet on the list lately, so I post a couple of helpful tips: Instead of using the "normal CPython" executable, I find it useful to choose [PathToSolution]/python.exe which is a Managed Code way of loading the pythonxx.dll and allows you to step out of the interpreter main loop when your script exits. Using a cool IDE (like Boa Constructor) which lets you set the interpreter, I also choose [PathToSolution]/python.exe. This makes running [PathToProject]/src/tests/runtests.py (which imports the Pythnon.Test managed test assembly) a snap! This all works thanks to the Post-build event command line of the projects: Python.Runtime: call "$(ProjectDir)buildclrmodule.bat" $(Platform) "$(ProjectDir)" "$(TargetDir)clr.pyd" copy "$(TargetPath)" "$(SolutionDir)" copy "$(TargetDir)*.pdb" "$(SolutionDir)" copy "$(TargetDir)clr.pyd" "$(SolutionDir)" Python.Test: copy "$(TargetPath)" "$(SolutionDir)" copy "$(TargetDir)*.pdb" "$(SolutionDir)" Speaking of runtests.py, it still doesn't run to completion. I'll be working on the Int64 issue shortly. Barton Windows 7 Python 2.6 From barton at BCDesignsWell.com Tue Jul 6 08:29:55 2010 From: barton at BCDesignsWell.com (Barton) Date: Mon, 05 Jul 2010 23:29:55 -0700 Subject: [Python.NET] Selecting an overloaded contructor Message-ID: <4C32CD63.8040304@BCDesignsWell.com> The readme clearly states that from System import String, Char, Int32 s = String.__overloads__[Char, Int32]('A', 10) should select the desired constructor, but ... there is clearly no means in the current (2.0.0.2) version for a ClassObject to activate the search by means of __getattribute__ (no tp_getattro). Is this something that worked in an earlier version? Where there changes that were made that were not committed to the trunk? Is this something that anybody else has come up against? fixed??? Thanks, all, Barton Windows 7, Framework Version: 2.0.50727.42 (AFAIK) Python 2.6.5 From joachim.lezard at gmail.com Tue Jul 13 17:08:27 2010 From: joachim.lezard at gmail.com (Joachim de Lezardiere) Date: Tue, 13 Jul 2010 17:08:27 +0200 Subject: [Python.NET] Some super basic/possibly stupid question Message-ID: <4c3c816b.2290d80a.1854.7797@mx.google.com> Hello Brian, I have looked at the help and nobody seems to be having my problem: 1. I install PythonNet (pythonnet-1.0-rc2-py2.3-clr1.1) at C:\Python27 2. Cmd and then, cd C:\Python27 3. Python.exe 4. Then I type: from System import String 5. And I get the error: No module named System. L Which is true, there are no module on my computer called System. So how can I import a module that doesn't exist ? Sorry for this possibly stupid question , Thanks, Joe -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave.hirschfeld at gmail.com Tue Jul 13 17:15:05 2010 From: dave.hirschfeld at gmail.com (Dave) Date: Tue, 13 Jul 2010 15:15:05 +0000 (UTC) Subject: [Python.NET] Some super basic/possibly stupid question References: <4c3c816b.2290d80a.1854.7797@mx.google.com> Message-ID: Joachim de Lezardiere writes: > > Which is true, there are no module > on my computer called System? So how can I import a module that > doesn?t exist ? > Did you import clr first? Type "help", "copyright", "credits" or "license" for more information. >>> import System Traceback (most recent call last): File "", line 1, in ImportError: No module named System >>> import clr >>> import System >>> System >>> NB: You should have copied the clr.pyd and Python.Runtime.dll files you compiled to the C:\Python27 directory as part of the "installation process" HTH, Dave From barton at BCDesignsWell.com Mon Jul 26 01:15:17 2010 From: barton at BCDesignsWell.com (Barton) Date: Sun, 25 Jul 2010 16:15:17 -0700 Subject: [Python.NET] Selecting an overloaded constructor + a MethodBinder.Bind patch In-Reply-To: <4C32CD63.8040304@BCDesignsWell.com> References: <4C32CD63.8040304@BCDesignsWell.com> Message-ID: <4C4CC585.6070406@BCDesignsWell.com> In case anyone is interested: I have added a Constructors object named '__overloads__' to the ClassObject.__dict__ that has the necessary machinery to select overloaded constructors using subscript notation, as in: from System import String, Char, Int32 s = String.__overloads__[Char, Int32]('A', 10) or from System import Array CharArrType = Array[Char] StringFromCharArr = String.__overloads__[CharArrType] s = StringFromCharArr(list('hello')) Just as in MethodObject, I implement a Descriptor __get__() in managed code that returns a CtorMapper for ctor selection and invoking. Also fixed a bug in MethodBinder.Bind() that threw an unhandled InvalidCastException when calling a non-static method on a class rather than on an instance of the class. Here's the patch as it stands: diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs index 862a110..f1bc042 100644 -- a/src/runtime/methodbinder.cs ++ b/src/runtime/methodbinder.cs @@ -294,23 +295,39 @@ namespace Python.Runtime { Object target = null; if ((!mi.IsStatic) && (inst != IntPtr.Zero)) { - CLRObject co = (CLRObject)ManagedType.GetManagedObject( - inst - ); + //CLRObject co = (CLRObject)ManagedType.GetManagedObject(inst); + // Calling on a ClassObject raises an unhandled exception: + // InvalidCastException: Unable to cast object of type + // 'Python.Runtime.ClassObject' to type 'Python.Runtime.CLRObject' + // + //ManagedType mt = ManagedType.GetManagedObject(inst); + // The above cast would fail if GetManagedObject(inst) returned null. + //CLRObject co = mt as CLRObject; + + CLRObject co = ManagedType.GetManagedObject(inst) as CLRObject; + + // Sanity check: this ensures a graceful exit if someone does + // something intentionally wrong like call a non-static method + // on the class rather than on an instance of the class. + // XXX maybe better to do this before all the other rigmarole. + if (co == null) { + return null; + } target = co.inst; } - + // target may or may not be null, here return new Binding(mi, target, margs, outs); } - } + } // END foreach MethodBase mi in _methods I sure with that we could get the maintainers of the SourceForge project to make some contact... possibly bring in some fresh blood to the project. On 7/5/2010 11:29 PM, Barton wrote: > The readme clearly states that > > from System import String, Char, Int32 > s = String.__overloads__[Char, Int32]('A', 10) > > should select the desired constructor, but ... > it doesn't > > Is this something that worked in an earlier version? > Where there changes that were made that were not committed to the trunk? > Is this something that anybody else has come up against? fixed??? > > Thanks, all, > Barton > Windows 7, Framework Version: 2.0.50727.42 (AFAIK) > Python 2.6.5 > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > From dave.hirschfeld at gmail.com Wed Jul 28 15:30:27 2010 From: dave.hirschfeld at gmail.com (Dave) Date: Wed, 28 Jul 2010 13:30:27 +0000 (UTC) Subject: [Python.NET] Selecting an overloaded constructor + a MethodBinder.Bind patch References: <4C32CD63.8040304@BCDesignsWell.com> <4C4CC585.6070406@BCDesignsWell.com> Message-ID: Barton writes: > > In case anyone is interested: > I have added a Constructors object named '__overloads__' to the > ClassObject.__dict__ that has the necessary machinery to select > overloaded constructors using subscript notation, as in: > from System import String, Char, Int32 > s = String.__overloads__[Char, Int32]('A', 10) > or > from System import Array > CharArrType = Array[Char] > StringFromCharArr = String.__overloads__[CharArrType] > s = StringFromCharArr(list('hello')) > > Just as in MethodObject, I implement a Descriptor __get__() in managed > code that returns a CtorMapper for ctor selection and invoking. > > Also fixed a bug in MethodBinder.Bind() that threw an unhandled > InvalidCastException when calling a non-static method on a class rather > than on an instance of the class. Here's the patch as it stands: > diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs > index 862a110..f1bc042 100644 Thanks for posting - could be useful for in future (I'm not using PythonDotNET much at the moment but will be again shortly.) Not sure if you've seen this but in the spirit of posting patches I thought I'd mention Alexey Borzenkov's patch: http://git.kitsu.ru/patched/pythonnet.git?a=commitdiff;h=995109e3ed27d6061dde5376f2968c9fbad894b7 Which fixes the problem of errors in constructors not being passed through to Python. HTH, Dave