[IronPython] Compiling into a DLL with pyc.py and then calling the class

Srivatsn Narayanan srivatsn at microsoft.com
Tue Aug 26 11:33:21 PDT 2008





-----Original Message-----
From: hellosticky [mailto:hellosticky at gmail.com]
Sent: Tuesday, August 26, 2008 11:22 AM
To: Srivatsn Narayanan; 'Discussion of IronPython'
Subject: RE: [IronPython] Compiling into a DLL with pyc.py and then calling the class



Thanks to both Srivatsn and Michael, that worked! I have a few comments/questions:



1. How do I get a list of all imported DLLs? If I do "dir()" I don't see my test DLL.

[Srivatsn] clr.References returns the list of referenced assemblies.



2. Is the name of the assembly used as the namespace for all of the classes in this assembly?

[Srivatsn] The name of the py files are used as the namespace. So if there are multiple py files compiled into one assembly, you would import each file by its name after adding the assembly reference.



Thanks,



> -----Original Message-----

> From: Srivatsn Narayanan [mailto:srivatsn at microsoft.com]

> Sent: Tuesday, August 26, 2008 2:15 PM

> To: hellosticky at gmail.com; Discussion of IronPython

> Subject: RE: [IronPython] Compiling into a DLL with pyc.py

> and then calling the class

>

> You are missing an import after adding the reference. This

> should work:

>

> clr.AddReference("test")

> from test import test

> t = test()

>

> There was also a bug with passing references with relative

> path (fixed now). If it blows up for you, try passing in the

> fully qualified assembly name.

>

> -----Original Message-----

> From: users-bounces at lists.ironpython.com

> [mailto:users-bounces at lists.ironpython.com] On Behalf Of hellosticky

> Sent: Tuesday, August 26, 2008 11:07 AM

> To: IronPython

> Subject: [IronPython] Compiling into a DLL with pyc.py and

> then calling the class

>

> Hi, I'm new to IronPython. I have the following test.py:

>

> from System import *

> from System.Collections.Generic import *

> from System.Text import *

> from PublicDomain import *

>

> class test:

>         def foo(self):

>                 return

> GlobalConstants.EarthEquatorialRadiusInKilometers

>

> PublicDomain is a package from here:

> http://www.codeplex.com/PublicDomain

>

> I compile this python file into a DLL with:

>

> ipy.exe pyc.py /out:test /target:dll

> /r:..\publicdomain\PublicDomain.dll test.py

>

> Everything looks good in ildasm. Then I load up ipy.exe:

>

> >ipy

> IronPython 2.0 Beta (2.0.0.4000) on .NET 2.0.50727.1433

> Type "help", "copyright", "credits" or "license" for more information.

> >>> import clr

> >>> clr.AddReference("test")

> >>> t = test()

> Traceback (most recent call last):

>   File "<stdin>", line 1, in <module>

> NameError: name 'test' is not defined

>

> Any ideas what I'm doing wrong?

>

> Thanks!

>

> _______________________________________________

> Users mailing list

> Users at lists.ironpython.com

> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

>

>




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ironpython.com/pipermail/users-ironpython.com/attachments/20080826/7dfa8816/attachment.htm>


More information about the Users mailing list