How to import only one module in a package when the package __init__.py has already imports the modules?

Peng Yu pengyu.ut at gmail.com
Sat Oct 31 23:48:10 EDT 2009


On Sat, Oct 31, 2009 at 9:18 PM, Dave Angel <davea at ieee.org> wrote:
> Peng Yu wrote:
>>
>> On Sat, Oct 31, 2009 at 5:45 PM, Wolodja Wentland
>> <wentland at cl.uni-heidelberg.de> wrote:
>>
>>>
>>> On Sat, Oct 31, 2009 at 16:53 -0500, Peng Yu wrote:
>>>
>>>>
>>>> On Sat, Oct 31, 2009 at 4:14 PM, Robert Kern <robert.kern at gmail.com>
>>>> wrote:
>>>>
>>>
>>> [ snip ]
>>>
>>>
>>>>
>>>> I know that multiple classes or functions are typically defined in one
>>>> file (i.e. module in python). However, I feel this make the code not
>>>> easy to read. Therefore, I insist on one class or function per file
>>>> (i.e module in python).
>>>>
>>>
>>> Are you serious? Do you *really* put each function in its own file? How
>>> exactly does this enhance the readability of the source code? Especially
>>> if you compare that to a (sic!) modularisation scheme that groups
>>> classes and functions together by task or semantic relatedness.
>>>
>>
>> <snip>
>> One advantage is on refactoring. When each function has its own file,
>> I can change variable names, etc., for a give function without
>> worrying accidentally change variable names in other functions. When I
>> find a function is more appropriate to put in another namespace, I can
>> just move the file around.
>>
>>
>
> Variables in a function are already private.  How can the names in one
> function be affected by other functions in the same module?

You misunderstood me.

If there are multiple functions or classes in a file, when I change
variables in a function/class, I have to make sure that they are not
in other functions or classes. This makes the refactoring process
tedious. If I have a single class/function in a file, I can safely
change variable names without worrying broken other classes or
functions.



More information about the Python-list mailing list