From ruszkait at gmail.com Wed Jul 1 08:35:42 2015 From: ruszkait at gmail.com (Tamas Ruszkai) Date: Wed, 1 Jul 2015 08:35:42 +0200 Subject: [Python.NET] Action delegate in Python 3.4 Message-ID: I have installed CPython 3.4 64bit and pythonnet-2.1.0.dev1-cp34-none-win_amd64.whl I have tried to use the generic action delegate, but failed. Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import clr >>> clr.AddReference("System") >>> import System >>> def hello(number): ... print(number) ... >>> deleg = System.Action[int](hello) Traceback (most recent call last): File "", line 1, in TypeError: unsubscriptable object >>> However when I want to instantiate a genrics dictionary then it works. >>> clr.AddReference("System.Collections") >>> import System.Collections.Generic >>> dict = System.Collections.Generic.Dictionary[int,str]() >>> dict[5]="asd" >>> print(dict[5]) asd -------------- next part -------------- An HTML attachment was scrubbed... URL: From tony at pyxll.com Wed Jul 1 18:09:33 2015 From: tony at pyxll.com (Tony Roberts) Date: Wed, 01 Jul 2015 16:09:33 +0000 Subject: [Python.NET] Action delegate in Python 3.4 In-Reply-To: References: Message-ID: Hi, looks like this just hasn't been implemented yet. I don't think it's specific to the 3.4 build. Could you create a github issue with your example if you get a chance? ( https://github.com/pythonnet/pythonnet/) If you want to have a go at implementing it yourself, take a look at the classes DelegateObject (delegateobject.cs) and GenericType (generictype.cs), and the method ClassManager.CreateClass in classmanager.cs. cheers, Tony On Wed, Jul 1, 2015 at 7:35 AM Tamas Ruszkai wrote: > I have installed CPython 3.4 64bit and > pythonnet-2.1.0.dev1-cp34-none-win_amd64.whl > > I have tried to use the generic action delegate, but failed. > > Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 > bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import clr > >>> clr.AddReference("System") > > >>> import System > >>> def hello(number): > ... print(number) > ... > >>> deleg = System.Action[int](hello) > Traceback (most recent call last): > File "", line 1, in > TypeError: unsubscriptable object > >>> > > However when I want to instantiate a genrics dictionary then it works. > > >>> clr.AddReference("System.Collections") > > >>> import System.Collections.Generic > >>> dict = System.Collections.Generic.Dictionary[int,str]() > >>> dict[5]="asd" > >>> print(dict[5]) > asd > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From germanocarella.list at gmail.com Fri Jul 3 13:50:25 2015 From: germanocarella.list at gmail.com (germano carella) Date: Fri, 03 Jul 2015 13:50:25 +0200 Subject: [Python.NET] python.net and autocompletion Message-ID: <55967701.50202@gmail.com> Hi, I'm attempting to write a python IDE accessible for blind persons. I'm a blind programmer and I need it to develop my applications. I'd like to create an autocompletion db containing all modules, functions, classes that a developer can use. Now, there is a way, with clr module, to retrieve list of available modules to import? Or, there is a way to implement a c# class that makes it possible? Thanks! Germano From brad at fie.us Mon Jul 6 18:47:04 2015 From: brad at fie.us (Bradley Friedman) Date: Mon, 6 Jul 2015 12:47:04 -0400 Subject: [Python.NET] python.net and autocompletion In-Reply-To: <55967701.50202@gmail.com> References: <55967701.50202@gmail.com> Message-ID: <8BFCB035-7259-4783-BD33-6EB533A06FD5@fie.us> This is not exactly what you asked for. However: WingIDE does this and uses a piece of open-source code to do it completely in python. A copy can be found here: http://www.voidspace.org.uk/downloads/generate_pi.py More up-to-date versions can be found within WingIDE installs themselves. This piece of code is open source and therefore available to you to use. It?s not a .net library. It?s pure python. It should be easily hacked-up and used by you to the same effect. It already exists and is in wide use. -brad -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.akhiyarov at gmail.com Thu Jul 9 17:51:39 2015 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Thu, 09 Jul 2015 15:51:39 +0000 Subject: [Python.NET] Debugging CPYTHON embedded in .NET Message-ID: Dear users and developers of PythonNET: How do you debug CPython embedded in . NET? Did you find any reliable way to do this with IDE such as PTVS or Pycharm? PTVS offers mixed-mode and remote debugging, none of which seem to be usable with PythonNET. Thanks, Denis -------------- next part -------------- An HTML attachment was scrubbed... URL: From tony at pyxll.com Fri Jul 10 10:23:31 2015 From: tony at pyxll.com (Tony Roberts) Date: Fri, 10 Jul 2015 08:23:31 +0000 Subject: [Python.NET] Debugging CPYTHON embedded in .NET In-Reply-To: References: Message-ID: Hi Denis, you can use the remote debugger in PyCharm to attach to your .NET process. It requires a small bit of python code in your application to make it connect to the PyCharm debug server, but it works very well. See the instructions here: http://blog.jetbrains.com/pycharm/2010/12/python-remote-debug-with-pycharm/ I've got an open request to enhance the new 'attach to process' feature that appeared in 4.0 so that it could attach to processes embedding python and not just python.exe (https://youtrack.jetbrains.com/issue/PY-14181), but for now using the debug server is your best option. Best regards, Tony On Thu, Jul 9, 2015 at 4:51 PM Denis Akhiyarov wrote: > Dear users and developers of PythonNET: > > How do you debug CPython embedded in . NET? > > Did you find any reliable way to do this with IDE such as PTVS or Pycharm? > > PTVS offers mixed-mode and remote debugging, none of which seem to be > usable with PythonNET. > > Thanks, > Denis > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From dlenski at gmail.com Tue Jul 21 06:00:14 2015 From: dlenski at gmail.com (Dan Lenski) Date: Tue, 21 Jul 2015 04:00:14 +0000 (UTC) Subject: [Python.NET] Getting an open Python file handle into CLR Message-ID: Hi, I posted this on StackOverflow but thought it might be a better question for this mailing list. http://stackoverflow.com/questions/31530059/how-can-i-open-a-net- filestream-object-from-a-python-file-handle I'm trying to figure out how to transform an open Python file handle into a System.IO.FileStream object so that I can pass it to C# code. Here's what I've got so far. This produces the good ol' win32 (HANDLE*) object, I believe: import clr, msvcrt from Microsoft.Win32.SafeHandles import SafeFileHandle from System.IO import FileStream, FileAccess from System import IntPtr, Int32, Int64 pyf=open("c:/temp/testing123.txt","w") fileno=pyf.fileno() print fileno # 6 handle = msvcrt.get_osfhandle(fileno) print handle # 1832L Unfortunately, I can't figure out how to convince the clr module to cast this handle into something that I can use as an IntPtr, as required by the constructors of FileStream or SafeFileHandle. I've tried various versions of the following, but they all give me TypeError ("value cannot be converted to System.IntPtr"): FileStream(IntPtr(handle), True) FileStream(IntPtr(Int32(handle), True) SafeFileHandle(IntPtr(handle), True) Thanks, Dan Lenski From rharding64 at yahoo.com Tue Jul 21 06:19:56 2015 From: rharding64 at yahoo.com (Ron Harding) Date: Tue, 21 Jul 2015 04:19:56 +0000 (UTC) Subject: [Python.NET] Getting an open Python file handle into CLR In-Reply-To: References: Message-ID: <1857701942.1607019.1437452396847.JavaMail.yahoo@mail.yahoo.com> perhaps re-directed command line calls for stdin, stdout, stderr in c# interacting with python i/o command line calls(although in python it is common practice to daisy chain commands). i have used this many times to get out of scrapes for 3rd party process calls in c#.? good luck! Ron??The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind. ?Nikola Tesla?Radio Power Will Revolutionize the World? (Modern Mechanix & Inventions, July, 1934) On Monday, July 20, 2015 9:05 PM, Dan Lenski wrote: Hi, I posted this on StackOverflow but thought it might be a better question for this mailing list. http://stackoverflow.com/questions/31530059/how-can-i-open-a-net- filestream-object-from-a-python-file-handle I'm trying to figure out how to transform an open Python file handle into a System.IO.FileStream object so that I can pass it to C# code. Here's what I've got so far. This produces the good ol' win32 (HANDLE*) object, I believe: import clr, msvcrt from Microsoft.Win32.SafeHandles import SafeFileHandle from System.IO import FileStream, FileAccess from System import IntPtr, Int32, Int64 pyf=open("c:/temp/testing123.txt","w") fileno=pyf.fileno() print fileno? ? ? ? ? ? ? # 6 handle = msvcrt.get_osfhandle(fileno) print handle? ? ? ? ? ? ? # 1832L Unfortunately, I can't figure out how to convince the clr module to cast this handle into something that I can use as an IntPtr, as required by the constructors of FileStream or SafeFileHandle. I've tried various versions of the following, but they all give me TypeError ("value cannot be converted to System.IntPtr"): FileStream(IntPtr(handle), True) FileStream(IntPtr(Int32(handle), True) SafeFileHandle(IntPtr(handle), True) Thanks, Dan Lenski _________________________________________________ Python.NET mailing list - PythonDotNet at python.org https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From dlenski at gmail.com Tue Jul 21 20:12:37 2015 From: dlenski at gmail.com (Dan Lenski) Date: Tue, 21 Jul 2015 18:12:37 +0000 (UTC) Subject: [Python.NET] Getting an open Python file handle into CLR References: <1857701942.1607019.1437452396847.JavaMail.yahoo@mail.yahoo.com> Message-ID: Ron Harding via PythonDotNet writes: > perhaps re-directed command line calls for stdin, stdout, stderr in c# interacting with python i/o command line calls(although in python it is common practice to daisy chain commands). Unfortunately, I cannot redirect the output of the C# library to a convenient filehandle like stdout/stderr; I need to be specify a FileStream object. It pretty much comes down to this: how do I cast a win32 file handle to an IntPtr? Thanks, Dan From rharding64 at yahoo.com Tue Jul 21 21:28:17 2015 From: rharding64 at yahoo.com (Ron Harding) Date: Tue, 21 Jul 2015 19:28:17 +0000 (UTC) Subject: [Python.NET] Getting an open Python file handle into CLR In-Reply-To: References: Message-ID: <976775015.2132890.1437506897205.JavaMail.yahoo@mail.yahoo.com> >how do I cast a win32 file handle to an?IntPtr? i ran into this in the past as well; specifically when i started using FTDI USB devices on DLPdesign development kits. ?the library is written in c++ MFC code. ?After providing data marshal/platform invoke i applied the intptr in c#. ? The USB device that I am accessing, passes a file handle to indicate specific pass / fail condition. ?i.e. the first command opens a connection to the device, the expected handle is 'OK'. ?if not one of many different possible error messages is passed in the file handle. ? SummaryOpen the device and return a handle which will be used for subsequent accesses.DefinitionFT_STATUS FT_Open (int iDevice, FT_HANDLE *ftHandle)ParametersiDevice Index of the device to open. Indices are 0 based.ftHandle Pointer to a variable of type FT_HANDLE where the handle will bestored. This handle must be used to access the device.Return ValueFT_OK if successful, otherwise the return value is an FT error code. public class Wrapper{private static IntPtr m_USBhandler; [DllImport("FTD2XX.dll", EntryPoint="FT_Open")]public static extern uint FT_Open(int iDevice, ref IntPtr ftHandle); [DllImport("FTD2XX.dll", EntryPoint="FT_Close")]public static extern uint FT_Close(IntPtr ftHandle); [DllImport("FTD2XX.dll", EntryPoint="FT_Read")]public static extern uint FT_Read(IntPtr ftHandle, byte[] lpBuffer,uint dwBytesToRead, ref uintlpdwBytesReturned); [DllImport("FTD2XX.dll", EntryPoint="FT_Write")]public static extern uint FT_Write(IntPtr ftHandle, byte[] lpBuffer,uint dwBytesToWrite, ref uintlpdwBytesWritten); [DllImport("FTD2XX.dll", EntryPoint="FT_Purge")]public static extern uint FT_Purge(IntPtr ftHandle, uint dwMask); public static bool OpenDevice(){if (((FT_Status)Wrapper.FT_Open(1, ref m_USBhandler)) ==FT_Status.Ok){return true;}else{return false;}} i hope this helps you by seeing one way of applying file handles in c#.? Ron???The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind.?Nikola Tesla?Radio Power Will Revolutionize the World? (Modern Mechanix & Inventions, July, 1934) On Tuesday, July 21, 2015 11:12 AM, Dan Lenski wrote: Ron Harding via PythonDotNet writes: > perhaps re-directed command line calls for stdin, stdout, stderr in c# interacting with python i/o command line calls(although in python it is common practice to daisy chain commands). Unfortunately, I cannot redirect the output of the C# library to a convenient filehandle like stdout/stderr; I need to be specify a FileStream object. It pretty much comes down to this: how do I cast a win32 file handle to an IntPtr? Thanks, Dan _________________________________________________ Python.NET mailing list - PythonDotNet at python.org https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeff at coderforlife.com Tue Jul 21 19:53:50 2015 From: jeff at coderforlife.com (Jeffrey Bush) Date: Tue, 21 Jul 2015 10:53:50 -0700 Subject: [Python.NET] Getting an open Python file handle into CLR In-Reply-To: <1857701942.1607019.1437452396847.JavaMail.yahoo@mail.yahoo.com> References: <1857701942.1607019.1437452396847.JavaMail.yahoo@mail.yahoo.com> Message-ID: The problem is the conversion from a Python long to a C# number, not anything to do with the file handle itself. This worked for me: (after your "print handle") cs_handle = IntPtr.Overloads[Int64](Int64(handle)) fs = FileStream(cs_handle, True) Jeff On Mon, Jul 20, 2015 at 9:19 PM, Ron Harding via PythonDotNet < pythondotnet at python.org> wrote: > perhaps re-directed command line calls for stdin, stdout, stderr in c# > interacting with python i/o command line calls(although in python it is > common practice to daisy chain commands). > > i have used this many times to get out of scrapes for 3rd party process > calls in c#. > > good luck! > > Ron > > ?The desire that guides me in all I do is the desire to harness the forces > of nature to the service of mankind. > > ?Nikola Tesla?Radio Power Will Revolutionize the World? (Modern Mechanix & > Inventions, July, 1934) > > > > On Monday, July 20, 2015 9:05 PM, Dan Lenski wrote: > > > Hi, > I posted this on StackOverflow but thought it might be a better question > for this mailing list. > > http://stackoverflow.com/questions/31530059/how-can-i-open-a-net- > filestream-object-from-a-python-file-handle > > I'm trying to figure out how to transform an open Python file handle > into a System.IO.FileStream object so that I can pass it to C# code. > > Here's what I've got so far. This produces the good ol' win32 (HANDLE*) > object, I believe: > > import clr, msvcrt > from Microsoft.Win32.SafeHandles import SafeFileHandle > from System.IO import FileStream, FileAccess > from System import IntPtr, Int32, Int64 > > pyf=open("c:/temp/testing123.txt","w") > fileno=pyf.fileno() > print fileno # 6 > handle = msvcrt.get_osfhandle(fileno) > print handle # 1832L > > Unfortunately, I can't figure out how to convince the clr module to cast > this handle into something that I can use as an IntPtr, as required by > the constructors of FileStream or SafeFileHandle. > > I've tried various versions of the following, but they all give me > TypeError ("value cannot be converted to System.IntPtr"): > > FileStream(IntPtr(handle), True) > FileStream(IntPtr(Int32(handle), True) > SafeFileHandle(IntPtr(handle), True) > > Thanks, > Dan Lenski > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeff at coderforlife.com Tue Jul 21 21:31:17 2015 From: jeff at coderforlife.com (Jeffrey Bush) Date: Tue, 21 Jul 2015 12:31:17 -0700 Subject: [Python.NET] Getting an open Python file handle into CLR In-Reply-To: References: <1857701942.1607019.1437452396847.JavaMail.yahoo@mail.yahoo.com> Message-ID: As I said in my message, you can using IntPtr.Overloads[Int64](handle). Jeff On Tue, Jul 21, 2015 at 11:12 AM, Dan Lenski wrote: > Ron Harding via PythonDotNet writes: > > > perhaps re-directed command line calls for stdin, stdout, stderr in c# > interacting with python i/o command line calls(although in python it is > common practice to daisy chain commands). > > Unfortunately, I cannot redirect the output of the C# library to a > convenient filehandle like stdout/stderr; I need to be specify a > FileStream object. > > It pretty much comes down to this: how do I cast a win32 file handle to an > IntPtr? > > Thanks, > Dan > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dlenski at gmail.com Wed Jul 22 00:54:50 2015 From: dlenski at gmail.com (Dan Lenski) Date: Tue, 21 Jul 2015 22:54:50 +0000 (UTC) Subject: [Python.NET] Getting an open Python file handle into CLR References: <1857701942.1607019.1437452396847.JavaMail.yahoo@mail.yahoo.com> Message-ID: Jeffrey Bush writes: > > > The problem is the conversion from a Python long to a C# number, not anything to do with the file handle itself. > This worked for me: (after your "print handle") > > > cs_handle = IntPtr.Overloads[Int64](Int64(handle)) > fs = FileStream(cs_handle, True) > Aha, thanks you very much! Looks like "Overloads" is the missing ingredient for C-style casting. I see now that that is in the docs, but I had overlooked it. Dan