[Tutor] module versus file
Kent Johnson
kent37 at tds.net
Thu Jun 8 15:28:27 CEST 2006
Kermit Rose wrote:
> Are you saying that any .py file that I save in math\factoring
> can be imported?
Yes
> You already have
> many modules installed as part of the standard library and any
> third-party add-ons you have installed.
>
> **********
>
> Yes. I'm impressed with the listing in built_in.
>
> I assumed system modules were handled in a different way than user modules.
Many system modules are written in Python and handled the same way as
user modules - they are found by searching sys.path. The actual files
are in C:\Python24\Lib
Some system modules are written in C, they are still on sys.path but the
modules are called .pyd.
Some system modules are built-in to Python and don't correspond to an
actual file in the file system.
>
> *********
>
>
> If you are working with a module from the interpreter and you make
> changes to the module, you have to reload it with the command
> >>> reload(factor30)
>
> *****
>
> I will try the reload command next time I work with factor30.
>
> This won't work for local names (from factor30 import xx)! Just use the
> full name to access any elements of factor30, e.G. factor30.gcd. Read
>
> ******
>
> In order to have the shorter name,
>
> gcd
>
> instead of factor30.gcd,
>
> I prepare by
>
> typing
>
> from factor30 import gcd
If you do this, reload(factor30) will not get you a new copy of gcd
because gcd is bound to the old function.
>
>
> Once someone said that modules and files are not the same thing.
>
> This statement left me puzzled. Why not?
Most modules do have corresponding files. The exceptions are the ones
built-in to Python. In fact modules have a __file__ attribute that tells
you where it came from; try typing
factor30.__file__
Kent
More information about the Tutor
mailing list