[Python.NET] RANGE object access from Python

2020-12-02 Thread AlexM
Hello, guys,
I have a C# object, I need access to it's properties in Python 2.7.
I got this type returned from a C# dll:
 
This should be a "Range" data type in C#.
Thanks a lot for any suggestion!
Alex.
___
PythonNet mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/pythonnet.python.org/
Member address: [email protected]


[Python.NET] Re: RANGE object access from Python

2020-12-02 Thread AlexM
Thank you very much Emmanuel !
I will try your idea, think this should work ...
Take care!
Alex.

On Wed, Dec 2, 2020 at 3:35 PM Emmanuel Rutovic  wrote:

> Hi Alex,
>
> Not sure about your class but you can use codecs to create custom code to
> convert your objects from .Net to Python.
>
> Doc :
> https://github.com/pythonnet/pythonnet/wiki/Codecs:-customizing-object-marshalling-between-.NET-and-Python
>
> Here is how I use it:
>
> public class DoubleArrayPythonEncoder : IPyObjectEncoder
>
>
> {
>
> public static DoubleArrayPythonEncoder Instance { get; } = new
> DoubleArrayPythonEncoder();
>
>
> public bool CanEncode(Type type)
>
> {
>
> return type == typeof(double[]);
>
> }
>
>
> public PyObject TryEncode(object value)
>
> {
>
>
> if (value is double[] doublearray)
>
> {
>
> var pyList = new PyList();
>
> for (int i = 0; i < doublearray.Length - 1; i++)
>
> {
>
> pyList.Append(new PyFloat(doublearray[i]));
>
> }
>
> return pyList;
>
> }
>
> return null;
>
> }
>
>
> public static void Register()
>
> {
>
> PyObjectConversions.RegisterEncoder(Instance);
>
> }
>
> }
>
> In Python, just call Register() before getting object.
>
> I hope it helps!
>
> Regards,
> *Emmanuel Rutovic*
> Founder, AESIM.tech
> [email protected]
> +1 (438) 926-6458
>
>
> On Dec 2, 2020 at 2:37:39 PM, AlexM  wrote:
>
>> ___
>> PythonNet mailing list -- [email protected]
>> To unsubscribe send an email to [email protected]
>> https://mail.python.org/mailman3/lists/pythonnet.python.org/
>> Member address: [email protected]
>>
> ___
> PythonNet mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/pythonnet.python.org/
> Member address: [email protected]
>
___
PythonNet mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/pythonnet.python.org/
Member address: [email protected]


[Python.NET] Re: Binary file passed to .Net object

2021-01-27 Thread AlexM
Manu, thank you very much for your suggestions...
So, far I have .dll and these are not the solutions.
Also, the exact same code works in IronPython, b.t.w.

Well, the error does come from the "ExamRecordLoader", here is the output:

c:\Test_MW\Tools\GuiTest>python getExamRecord.py
Load Exam Record
Could not load Exam Record:  Error loading ExamRecord binary file:
C:\\Test_MW\\Tools\\ExamRecords\\Resp4DCT Column requires a valid DataType.
   at ExamRecordHelper.ExamRecordLoader.LoadExamRecord(String filename)
   at ExamRecordHelper.ExamRecordLoader..ctor(String filename)

And this is the source:

import clr
try:
ExRHelperAsseblyRef =
clr.AddReference("C:\\Test_MW\\Tools\\GuiTest\\ExamRecordHelper.dll")
from ExamRecordHelper import *

except Exception, e:
print("Exception : " + str(e))

# path to binary file:
examRecordFile = r'C:\\Test_MW\\Tools\\ExamRecords\\Resp4DCT'

try:
print "Load Exam Record"
exrec = ExamRecordLoader(examRecordFile) # <
Exception line
stepList=exrec.GetStepList()
print "stepList="+str(stepList)
except Exception as e:
print "Could not load Exam Record: ", str(e)

Alex.

On Wed, Jan 27, 2021 at 3:54 PM Emmanuel Rutovic  wrote:

> Hi Alex,
>
> It seems that the exception is thrown inside your method
> "ExamRecordLoader" so it is hard to debug.
> Is it possible that the error is thrown because of different working
> directories? Can you try to use the full path to 'MyBinaryFile.bin' ?
>
> Also, I always use the file name including the extension (
> clr.AddReference("C:\ExamRecordHelper*.dll*") ) but I doubt it will
> change anything
>
> I hope it helps,
> Manu.
>
>
>
> On Wed, Jan 27, 2021 at 2:47 PM Alexander Masis 
> wrote:
>
>> The code in the original post works in IronPython ( i.e. loaderObj =
>> ExamRecordLoader( 'MyBinaryFile.bin') this line has no exceptions in
>> IronPython )
>> ___
>> PythonNet mailing list -- [email protected]
>> To unsubscribe send an email to [email protected]
>> https://mail.python.org/mailman3/lists/pythonnet.python.org/
>> Member address: [email protected]
>>
> ___
> PythonNet mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/pythonnet.python.org/
> Member address: [email protected]
>
___
PythonNet mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/pythonnet.python.org/
Member address: [email protected]


[Python.NET] Re: Binary file passed to .Net object

2021-01-28 Thread AlexM
Victor, thanks for your response.
I did try a simple C# test code and it's working as expected.
So, both C# and IronPython calls work, but I still need Python.Net  to work.
Alex,
Спасибо..

On Wed, Jan 27, 2021 at 8:27 PM Victor “LOST” Milovanov <
[email protected]> wrote:

> Can you try this from C# interactive (or plain C#)?
>
>
>
> #r "C:\Test_MW\Tools\GuiTest\ExamRecordHelper.dll"
>
> using ExamRecordHelper;
>
>
>
> var record = new
> ExamRecordLoader("C:\\Test_MW\\Tools\\ExamRecords\\Resp4DCT");
>
>
>
> Without having ExamRecordHelper.dll, it is hard to guess otherwise, but I
> agree with Manu, this looks like a mistake in the code (different files
> and/or different versions of the DLL being loaded).
>
>
>
> Regards,
>
> Victor
>
>
>
> *From: *AlexM 
> *Sent: *Wednesday, January 27, 2021 5:16 PM
> *To: *A list for users and developers of Python.NET 
> *Subject: *[Python.NET] Re: Binary file passed to .Net object
>
>
>
> Manu, thank you very much for your suggestions...
>
> So, far I have .dll and these are not the solutions.
>
> Also, the exact same code works in IronPython, b.t.w.
>
>
>
> Well, the error does come from the "ExamRecordLoader", here is the output:
>
>
>
> c:\Test_MW\Tools\GuiTest>python getExamRecord.py
> Load Exam Record
> Could not load Exam Record:  Error loading ExamRecord binary file:
> C:\\Test_MW\\Tools\\ExamRecords\\Resp4DCT Column requires a valid DataType.
>at ExamRecordHelper.ExamRecordLoader.LoadExamRecord(String filename)
>at ExamRecordHelper.ExamRecordLoader..ctor(String filename)
>
>
>
> And this is the source:
>
>
>
> import clr
> try:
> ExRHelperAsseblyRef =
> clr.AddReference("C:\\Test_MW\\Tools\\GuiTest\\ExamRecordHelper.dll")
> from ExamRecordHelper import *
>
> except Exception, e:
> print("Exception : " + str(e))
>
>
>
> # path to binary file:
> examRecordFile = r'C:\\Test_MW\\Tools\\ExamRecords\\Resp4DCT'
>
> try:
> print "Load Exam Record"
> exrec = ExamRecordLoader(examRecordFile) # <<<<<<<<<<<<<<<<<<<<<
> Exception line
> stepList=exrec.GetStepList()
> print "stepList="+str(stepList)
> except Exception as e:
> print "Could not load Exam Record: ", str(e)
>
>
>
> Alex.
>
>
>
> On Wed, Jan 27, 2021 at 3:54 PM Emmanuel Rutovic  wrote:
>
> Hi Alex,
>
>
>
> It seems that the exception is thrown inside your method
> "ExamRecordLoader" so it is hard to debug.
>
> Is it possible that the error is thrown because of different working
> directories? Can you try to use the full path to 'MyBinaryFile.bin' ?
>
>
>
> Also, I always use the file name including the extension (
> clr.AddReference("C:\ExamRecordHelper*.dll*") ) but I doubt it will
> change anything
>
>
>
> I hope it helps,
>
> Manu.
>
>
>
>
>
>
>
> On Wed, Jan 27, 2021 at 2:47 PM Alexander Masis 
> wrote:
>
> The code in the original post works in IronPython ( i.e. loaderObj =
> ExamRecordLoader( 'MyBinaryFile.bin') this line has no exceptions in
> IronPython )
> ___
> PythonNet mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/pythonnet.python.org/
> Member address: [email protected]
>
> ___
> PythonNet mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/pythonnet.python.org/
> Member address: [email protected]
>
>
> ___
> PythonNet mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/pythonnet.python.org/
> Member address: [email protected]
>
___
PythonNet mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/pythonnet.python.org/
Member address: [email protected]


[Python.NET] Re: Binary file passed to .Net object

2021-01-28 Thread AlexM
I have uploaded the dlls and sources to the dropbox, Victor. Check your
email(  [email protected] )

On Wed, Jan 27, 2021 at 8:27 PM Victor “LOST” Milovanov <
[email protected]> wrote:

> Can you try this from C# interactive (or plain C#)?
>
>
>
> #r "C:\Test_MW\Tools\GuiTest\ExamRecordHelper.dll"
>
> using ExamRecordHelper;
>
>
>
> var record = new
> ExamRecordLoader("C:\\Test_MW\\Tools\\ExamRecords\\Resp4DCT");
>
>
>
> Without having ExamRecordHelper.dll, it is hard to guess otherwise, but I
> agree with Manu, this looks like a mistake in the code (different files
> and/or different versions of the DLL being loaded).
>
>
>
> Regards,
>
> Victor
>
>
>
> *From: *AlexM 
> *Sent: *Wednesday, January 27, 2021 5:16 PM
> *To: *A list for users and developers of Python.NET 
> *Subject: *[Python.NET] Re: Binary file passed to .Net object
>
>
>
> Manu, thank you very much for your suggestions...
>
> So, far I have .dll and these are not the solutions.
>
> Also, the exact same code works in IronPython, b.t.w.
>
>
>
> Well, the error does come from the "ExamRecordLoader", here is the output:
>
>
>
> c:\Test_MW\Tools\GuiTest>python getExamRecord.py
> Load Exam Record
> Could not load Exam Record:  Error loading ExamRecord binary file:
> C:\\Test_MW\\Tools\\ExamRecords\\Resp4DCT Column requires a valid DataType.
>at ExamRecordHelper.ExamRecordLoader.LoadExamRecord(String filename)
>at ExamRecordHelper.ExamRecordLoader..ctor(String filename)
>
>
>
> And this is the source:
>
>
>
> import clr
> try:
> ExRHelperAsseblyRef =
> clr.AddReference("C:\\Test_MW\\Tools\\GuiTest\\ExamRecordHelper.dll")
> from ExamRecordHelper import *
>
> except Exception, e:
> print("Exception : " + str(e))
>
>
>
> # path to binary file:
> examRecordFile = r'C:\\Test_MW\\Tools\\ExamRecords\\Resp4DCT'
>
> try:
> print "Load Exam Record"
> exrec = ExamRecordLoader(examRecordFile) # <<<<<<<<<<<<<<<<<<<<<
> Exception line
> stepList=exrec.GetStepList()
> print "stepList="+str(stepList)
> except Exception as e:
> print "Could not load Exam Record: ", str(e)
>
>
>
> Alex.
>
>
>
> On Wed, Jan 27, 2021 at 3:54 PM Emmanuel Rutovic  wrote:
>
> Hi Alex,
>
>
>
> It seems that the exception is thrown inside your method
> "ExamRecordLoader" so it is hard to debug.
>
> Is it possible that the error is thrown because of different working
> directories? Can you try to use the full path to 'MyBinaryFile.bin' ?
>
>
>
> Also, I always use the file name including the extension (
> clr.AddReference("C:\ExamRecordHelper*.dll*") ) but I doubt it will
> change anything
>
>
>
> I hope it helps,
>
> Manu.
>
>
>
>
>
>
>
> On Wed, Jan 27, 2021 at 2:47 PM Alexander Masis 
> wrote:
>
> The code in the original post works in IronPython ( i.e. loaderObj =
> ExamRecordLoader( 'MyBinaryFile.bin') this line has no exceptions in
> IronPython )
> ___
> PythonNet mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/pythonnet.python.org/
> Member address: [email protected]
>
> ___
> PythonNet mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/pythonnet.python.org/
> Member address: [email protected]
>
>
> ___
> PythonNet mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/pythonnet.python.org/
> Member address: [email protected]
>
___
PythonNet mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/pythonnet.python.org/
Member address: [email protected]