Where is path.py?

Dave Angel davea at davea.name
Thu Nov 27 10:34:51 EST 2014


On 11/27/2014 09:10 AM, David Aldrich wrote:
> Hi
>
> I am running Python 2.7 on Windows 8.1. Today I installed path.py using easy_install:
>
> 	easy_install path.py
>
> The example code that I've seen imports path.py as follows:
>
> 	from path import path
>
> I am fairly new to Python and have a few questions about this:
>
> 1) Why is 'from path' required here?
>

The module called "path" evidently has a global symbol "path" in it. 
That's unfortunate and very confusing, but it's pretty common.  (See the 
time function in the time module, standard library.)  I don't know 
anything about the module, but I'll make a wild guess that path is a 
function.  It doesn't matter, but it'll let me make explicit examples.

So the obvious approach to dealing with a module is to import it.

import path

At that point, to call the above mentioned function, you would need to use:

result =  path.path(arguments)

That gets confusing, so you might want a shortcut:

pathfunc = path.path

and now you can use

result =  pathfunc(arguments)

The "from" logic facilitates that, by combining the import with the 
assignment:  The line:

from path import path
is equivalent to
import path;  path = path.path


I don't know where path.py is, and it might be called something else, 
such as path.pyc, or path.pyd, or ...  But you can probably search for 
it, if you like, with something like

     dir /s  c:\path.p*

I am assuming you're running on Windows, because you mention a Microsoft 
IDE.  If you were on Linux or Unix or Mac, you'd presumably use the find 
program.

 >
 > 2) I am using Microsoft's PTVS IDE to develop my code. It is not 
displaying code completion for path.py (it works for the standard 
libraries). How would I tell PTVS about path.py?


No clue about Microsoft's PTVS IDE;  I hadn't heard of it before.  But 
if somebody else doesn't jump in, you should be able to use the Python
   dir() and help() built-in functions.  Then only work if the path 
module is well written, of course.

-- 
DaveA



More information about the Python-list mailing list