Discussion:
[Python.NET] Importing .NET assembly with "." (dot) in the name
Mikhail Karmyshev
2013-04-30 02:15:47 UTC
Permalink
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.
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-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Mark Tigges
2013-04-30 15:21:41 UTC
Permalink
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
Post by Mikhail Karmyshev
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.
import Accord.Imaging
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
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
Mikhail Karmyshev
2013-04-30 16:01:24 UTC
Permalink
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.
Post by Mark Tigges
import is namespace on the AddReference.
namespace AccordImaging
{
.......
import AccordImaging
After you AddReference
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.
import Accord.Imaging
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
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
b***@public.gmane.org
2013-04-30 20:22:59 UTC
Permalink
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.
Post by Mikhail Karmyshev
Post by Mark Tigges
import clr
import System.IO
System.IO.Path.Combine('foo','bar')
u'foo/bar'
"""

-brad
Post by Mikhail Karmyshev
Mark, thank you for your help.
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.
Post by Mark Tigges
import is namespace on the AddReference.
namespace AccordImaging
{
.......
import AccordImaging
After you AddReference
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.
import Accord.Imaging
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
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
--
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
_________________________________________________
Python.NET mailing list - ***@python.org
http:

Loading...