[Python.NET] How to get 'None' from .NET?
Hello,
I'm trying to call from .NET some function defined in
a Python script, and pass 'null' as one of the
parameters of the function in certain situations. I
was expecting that the bridge would map the 'null' in
.NET to 'None' in Python, however I receive an
exception in .NET when I execute the code.
I have something like the following:
--
1. PyObject module =
PythonEngine.ImportModule("script")
2. PyObject func = module.GetAttr("someFunction")
3. object aNullObject = null
4. PyObject[] arguments = new PyObject[2]
5. arguments[0] = PyObject.FromManagedObject("a
string")
6. arguments[1] =
PyObject.FromManagedObject(aNullObject)
// I also tried: arguments[1] = null directly
8. func.Invoke(arguments)
When executed, line 6 throws a NullReferenceException
if I use 'arguments[1] = null' instead of line 6, I
get a NullReferenceException in line 8.
How can I pass 'null' to a script?
Thank you.
Boris
__
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
_
Python.NET mailing list - [email protected]
http://mail.python.org/mailman/listinfo/pythondotnet
[Python.NET] ActivePython 2.4.1.245 problem
Hi, I just upgraded my Python to ActiveState's 2.4.1 version and some thing apparently broke in the bridge. Here are some things I was able to do in version 2.4.0 that now no longer work: C:\Python24>python ActivePython 2.4.1 Build 245 (ActiveState Corp.) based on Python 2.4.1 (#65, Mar 30 2005, 09:33:37) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import CLR >>> from CLR.System.Reflection import Assembly Traceback (most recent call last): File "", line 1, in ? ImportError: __import__ not found >>> - C:\Python24>python ActivePython 2.4.1 Build 245 (ActiveState Corp.) based on Python 2.4.1 (#65, Mar 30 2005, 09:33:37) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import CLR >>> import CLR Traceback (most recent call last): File "", line 1, in ? ImportError: __import__ not found >>> >>> import os Traceback (most recent call last): File "", line 1, in ? ImportError: __import__ not found >>> It looks that after you first "import CLR" something gets screwed up inside CPython's tables because it can't find any imports anymore. Anyone else have the same problem? Boris __ Do you Yahoo!? Make Yahoo! your home page http://www.yahoo.com/r/hs _ Python.NET mailing list - [email protected] http://mail.python.org/mailman/listinfo/pythondotnet
RE: [Python.NET] ActivePython 2.4.1.245 problem
Hi Boris - this is actually fixed in my local copy (hope to check it in and make a new release soon, as this will affect anyone using the bootstrap hook in a native CPython). As a temporary workaround, you can arrange to hold a reference to the globals dictionary someplace before importing the CLR module: import sys sys._hack = globals() # now you can import CLR... import CLR Brian Lloyd[EMAIL PROTECTED] V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Boris Capitanu > Sent: Thursday, April 14, 2005 2:12 PM > To: [email protected] > Subject: [Python.NET] ActivePython 2.4.1.245 problem > > > Hi, > > I just upgraded my Python to ActiveState's 2.4.1 > version and some thing apparently broke in the bridge. > > Here are some things I was able to do in version 2.4.0 > that now no longer work: > > C:\Python24>python > ActivePython 2.4.1 Build 245 (ActiveState Corp.) based > on > Python 2.4.1 (#65, Mar 30 2005, 09:33:37) [MSC v.1310 > 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for > more information. > >>> import CLR > >>> from CLR.System.Reflection import Assembly > Traceback (most recent call last): > File "", line 1, in ? > ImportError: __import__ not found > >>> > > > - > > C:\Python24>python > ActivePython 2.4.1 Build 245 (ActiveState Corp.) based > on > Python 2.4.1 (#65, Mar 30 2005, 09:33:37) [MSC v.1310 > 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for > more information. > >>> import CLR > >>> import CLR > Traceback (most recent call last): > File "", line 1, in ? > ImportError: __import__ not found > >>> > >>> import os > Traceback (most recent call last): > File "", line 1, in ? > ImportError: __import__ not found > >>> > > > It looks that after you first "import CLR" something > gets screwed up inside CPython's tables because it > can't find any imports anymore. > > Anyone else have the same problem? > > Boris > > > > > __ > Do you Yahoo!? > Make Yahoo! your home page > http://www.yahoo.com/r/hs > _ > Python.NET mailing list - [email protected] > http://mail.python.org/mailman/listinfo/pythondotnet > _ Python.NET mailing list - [email protected] http://mail.python.org/mailman/listinfo/pythondotnet
RE: [Python.NET] How to get 'None' from .NET?
FromManagedObject wasn't handling this correctly - I've added
a fix for the next release. In the meantime, the easiest thing
to do is something like:
PyObject module = PythonEngine.ImportModule("script")
PyObject none = module.GetAttr("aliasForNone")
(this presumes that in the module you have created the name
'aliasForNone' and assigned it to None)
Brian Lloyd[EMAIL PROTECTED]
V.P. Engineering 540.361.1716
Zope Corporation http://www.zope.com
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of Boris Capitanu
> Sent: Thursday, April 14, 2005 1:38 PM
> To: [email protected]
> Subject: [Python.NET] How to get 'None' from .NET?
>
>
> Hello,
>
> I'm trying to call from .NET some function defined in
> a Python script, and pass 'null' as one of the
> parameters of the function in certain situations. I
> was expecting that the bridge would map the 'null' in
> .NET to 'None' in Python, however I receive an
> exception in .NET when I execute the code.
>
> I have something like the following:
>
> --
> 1. PyObject module =
> PythonEngine.ImportModule("script")
> 2. PyObject func = module.GetAttr("someFunction")
>
> 3. object aNullObject = null
>
> 4. PyObject[] arguments = new PyObject[2]
> 5. arguments[0] = PyObject.FromManagedObject("a
> string")
> 6. arguments[1] =
> PyObject.FromManagedObject(aNullObject)
> // I also tried: arguments[1] = null directly
>
> 8. func.Invoke(arguments)
>
>
> When executed, line 6 throws a NullReferenceException
> if I use 'arguments[1] = null' instead of line 6, I
> get a NullReferenceException in line 8.
>
> How can I pass 'null' to a script?
>
> Thank you.
>
> Boris
>
>
>
> __
> Do you Yahoo!?
> Yahoo! Small Business - Try our new resources site!
> http://smallbusiness.yahoo.com/resources/
> _
> Python.NET mailing list - [email protected]
> http://mail.python.org/mailman/listinfo/pythondotnet
>
_
Python.NET mailing list - [email protected]
http://mail.python.org/mailman/listinfo/pythondotnet
