[Python.NET] Importin­g .NET assembly with "." ­(dot) in the name

brad at fie.us brad at fie.us
Tue Apr 30 22:22:59 CEST 2013


You are confused.  Mark was pointing out that since an assembly is not necessarily named on disk, the same as the namespaces within it, you need to AddReference the assembly on disk, and THEN import the namespace.  And the namespace may not be named the same as the reference.

PythonNet is perfectly capable of importing a nested dot delimited namespace.

"""
fiellcmbp01:pythonnet bfriedman$ cd system_2.7-ucs2_fie-mono-64_osx_2.10.9/
fiellcmbp01:system_2.7-ucs2_fie-mono-64_osx_2.10.9 bfriedman$ ls
Python.Runtime.dll		clr.pyd
Python.Runtime.dll.config	clr.so
fiellcmbp01:system_2.7-ucs2_fie-mono-64_osx_2.10.9 bfriedman$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> import System.IO
>>> System.IO.Path.Combine('foo','bar')
u'foo/bar'
>>> 
"""

-brad

On Apr 30, 2013, at 12:01 PM, Mikhail Karmyshev <kmike at hotbox.ru> wrote:

> Mark, thank you for your help.
> Too bad that the original assembly which I am trying to use has namespace with "." in it:
> namespace Accord.Imaging{
> }
> 
> So in C#  "using Accord.Imaging'" works fine, but how to deal with it from Python?
> Sure, I can write a "wrapper" application without dots in namespace, I tested it and it works.
> But of course cleaner solution would be nice.
> 
> 
> Втр 30 Апр 2013 22:21:42 +0700, Mark Tigges <mtigges at gmail.com> написал:
>> import is namespace on the AddReference.
>> 
>> The import hooks look in the dll's that you've referenced, and search for namespaces as per the argument to Accord.  So, you shouldn't import the dll name.  If the assembly defines the namespace:
>> 
>> namespace AccordImaging
>> {
>> .......
>> 
>> Then, you should:
>> 
>> import AccordImaging
>> 
>> After you AddReference
>> 
>> On Mon, Apr 29, 2013 at 7:15 PM, Mikhail Karmyshev <kmike at hotbox.ru> wrote:
>> Hello,
>> Sorry for possibly dumb question, but is it possible to import an assembly with "." (dot) in the name ?
>> Without dot, for example "SlimDX.dll" - AddReference works and import works too.
>> But for "Accord.Imaging.dll" - AddReference is OK, but import fails:
>>>>> import Accord.Imaging
>> Traceback (most recent call last):
>>  File "<stdin>", line 1, in <module>
>> ImportError: No module named Accord
>> 
>> Is there a workaround for this or am I doing something wrong?
>> Any help appreciated.
>> Mikhail
>> _________________________________________________
>> Python.NET mailing list - PythonDotNet at python.org
>> http://mail.python.org/mailman/listinfo/pythondotnet
> 
> --
> _________________________________________________
> Python.NET mailing list - PythonDotNet at python.org
> http://mail.python.org/mailman/listinfo/pythondotnet



More information about the PythonDotNet mailing list