Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95223 > unrolled thread
| Started by | MRAB <python@mrabarnett.plus.com> |
|---|---|
| First post | 2015-08-10 16:48 +0100 |
| Last post | 2015-08-11 12:40 +1000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Importing is partially working... MRAB <python@mrabarnett.plus.com> - 2015-08-10 16:48 +0100
Re: Importing is partially working... Steven D'Aprano <steve@pearwood.info> - 2015-08-11 12:40 +1000
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2015-08-10 16:48 +0100 |
| Subject | Re: Importing is partially working... |
| Message-ID | <mailman.44.1439221743.3627.python-list@python.org> |
On 2015-08-10 11:11, Chris Angelico wrote: > On Sun, Aug 9, 2015 at 3:45 PM, Dwight GoldWinde <Dwight@goldwinde.com> wrote: >> name = 'Jim' >> coach = 'Dwight' >> import importlib >> sentence = 'Hi, there, ' + name + '. My name is ' + coach + '. I will be >> your coach today.' >> from Functions.py import humprint >> humprint (sentence) >> >> Traceback (most recent call last): >> >> File "Intro.py", line 5, in <module> >> >> from Functions.py import humprint >> >> ImportError: No module named 'Functions.py'; 'Functions' is not a package >> >> >> >> So, it seems like it is accessing the module, but not the function? > > You're almost there! But in Python, you don't import something from a > specific file - you import from a module, and the Python interpreter > is free to locate that file anywhere that it can. It might be > implemented in C, and be stored in Functions.so (on Unix-like systems) > or Functions.dll (on Windows); it might be precompiled and loaded from > Functions.pyc; it might come from a zip file, or some other form of > special import source. So all you say is: > On Windows, the extension for Python extension DLLs is ".pyd". > from Functions import humprint > > and Python does the rest. Yep, that's all the change you need, and > your code will most likely work. (I haven't tested it, but it'll > probably work.) >
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2015-08-11 12:40 +1000 |
| Message-ID | <55c960aa$0$1668$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #95223 |
On Tue, 11 Aug 2015 01:48 am, MRAB wrote: > On Windows, the extension for Python extension DLLs is ".pyd". I believe that there is a subtle difference in the entry-point depending on whether the file is named .pyd or .dll. http://effbot.org/pyfaq/is-a-pyd-file-the-same-as-a-dll.htm https://docs.python.org/2/faq/windows.html#is-a-pyd-file-the-same-as-a-dll I'm not entirely sure, but I think the only way to access a DLL proper is via cytpes (or some other third-party framework, like Boost or SWIG). To actually use "import spam" on a DLL, you have to make sure it has an initfoo() function, and declare the list of available functions somewhat differently. Oh, and according to this: https://docs.python.org/2/extending/windows.html prior to Python 2.5, spam.dll was recognised by import. That was specifically changed so that you could have a spam.dll C library and a spam.pyd interface to that library. -- Steven
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web