How to import only one module in a package when the package __init__.py has already imports the modules?
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sun Nov 1 01:40:06 EDT 2009
On Sat, 31 Oct 2009 22:48:10 -0500, Peng Yu wrote:
>> 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.
No you don't.
def f(x):
return x+1
def g(x):
return x-1
If I choose to refactor f() and change "x" to "y", why do I care about
the internal variable inside g()?
Oh wait, I get it... you want to do a global search-and-replace over the
entire file. *face-palm*
If your functions are less than one-screen full, why do you need a global
replacement? Global replacement risks changing words in docstrings,
comments etc that it shouldn't.
--
Steven
More information about the Python-list
mailing list