Re: Why 'import module' will not import module.py but the directory module?

2009-11-01 Thread Colin W.

Robert Kern wrote:

On 2009-10-31 19:16 PM, Peng Yu wrote:
On Sat, Oct 31, 2009 at 7:02 PM, Robert Kernrobert.k...@gmail.com  
wrote:

On 2009-10-31 18:51 PM, Peng Yu wrote:


If I have both the directory 'module' and the file 'module.py' in a
directory in $PYTHONPATH, python will import 'module' rather than
'module.py'. I'm wondering what is the design rationale of setting
higher priorities to directories. Is there a way to reverse the
priority?


You mean that you have a package module/? With an __init__.py? Plain
directories that aren't packages shouldn't be imported by Python.


Yes. I mean a pakcage 'module/' with an __init__.py.


No, you can't reverse the priority between packages and modules. I'm not
sure why that would help you. The package would then be inaccessible 
if you

did. If it's inaccessible, then why have it at all?


Why the package 'module' has to be inaccessible? I can 'import
module.part1' to access the component of the package.


No, it wouldn't. It's a moot point because Python picks the package 
first, but if it did pick modules before packages, then 
sys.modules['module'] would point to the module from module.py and not 
module/__init__.py . import module.part1 first executes import 
module, then looks in there to determine who to resolve module.part1. 
Since sys.modules['module'] is a regular module and not the package, it 
wouldn't find module/part1.py .


Doesn't it make sense to avoid the use of names like module or package, 
even though they are permitted.


Colin W.
--
http://mail.python.org/mailman/listinfo/python-list


Why 'import module' will not import module.py but the directory module?

2009-10-31 Thread Peng Yu
If I have both the directory 'module' and the file 'module.py' in a
directory in $PYTHONPATH, python will import 'module' rather than
'module.py'. I'm wondering what is the design rationale of setting
higher priorities to directories. Is there a way to reverse the
priority?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why 'import module' will not import module.py but the directory module?

2009-10-31 Thread Robert Kern

On 2009-10-31 18:51 PM, Peng Yu wrote:

If I have both the directory 'module' and the file 'module.py' in a
directory in $PYTHONPATH, python will import 'module' rather than
'module.py'. I'm wondering what is the design rationale of setting
higher priorities to directories. Is there a way to reverse the
priority?


You mean that you have a package module/? With an __init__.py? Plain 
directories that aren't packages shouldn't be imported by Python.


No, you can't reverse the priority between packages and modules. I'm not sure 
why that would help you. The package would then be inaccessible if you did. If 
it's inaccessible, then why have it at all?


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


Re: Why 'import module' will not import module.py but the directory module?

2009-10-31 Thread Peng Yu
On Sat, Oct 31, 2009 at 7:02 PM, Robert Kern robert.k...@gmail.com wrote:
 On 2009-10-31 18:51 PM, Peng Yu wrote:

 If I have both the directory 'module' and the file 'module.py' in a
 directory in $PYTHONPATH, python will import 'module' rather than
 'module.py'. I'm wondering what is the design rationale of setting
 higher priorities to directories. Is there a way to reverse the
 priority?

 You mean that you have a package module/? With an __init__.py? Plain
 directories that aren't packages shouldn't be imported by Python.

Yes. I mean a pakcage 'module/' with an __init__.py.

 No, you can't reverse the priority between packages and modules. I'm not
 sure why that would help you. The package would then be inaccessible if you
 did. If it's inaccessible, then why have it at all?

Why the package 'module' has to be inaccessible? I can 'import
module.part1' to access the component of the package.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why 'import module' will not import module.py but the directory module?

2009-10-31 Thread Robert Kern

On 2009-10-31 19:16 PM, Peng Yu wrote:

On Sat, Oct 31, 2009 at 7:02 PM, Robert Kernrobert.k...@gmail.com  wrote:

On 2009-10-31 18:51 PM, Peng Yu wrote:


If I have both the directory 'module' and the file 'module.py' in a
directory in $PYTHONPATH, python will import 'module' rather than
'module.py'. I'm wondering what is the design rationale of setting
higher priorities to directories. Is there a way to reverse the
priority?


You mean that you have a package module/? With an __init__.py? Plain
directories that aren't packages shouldn't be imported by Python.


Yes. I mean a pakcage 'module/' with an __init__.py.


No, you can't reverse the priority between packages and modules. I'm not
sure why that would help you. The package would then be inaccessible if you
did. If it's inaccessible, then why have it at all?


Why the package 'module' has to be inaccessible? I can 'import
module.part1' to access the component of the package.


No, it wouldn't. It's a moot point because Python picks the package first, but 
if it did pick modules before packages, then sys.modules['module'] would point 
to the module from module.py and not module/__init__.py . import module.part1 
first executes import module, then looks in there to determine who to resolve 
module.part1. Since sys.modules['module'] is a regular module and not the 
package, it wouldn't find module/part1.py .


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list