from-import on non-module objects?
Rainer Deyke
root at rainerdeyke.com
Wed Jan 31 14:49:26 EST 2001
"Hamish Lawson" <hamish_lawson at yahoo.co.uk> wrote in message
news:959jna$nfl$1 at nnrp1.deja.com...
> class AClass:
>
> def __init__(self, x, y):
> self.x = x
> self.y = y
>
> def output(self):
> from self import *
> print x, y
This probably won't ever be added to Python for two reasons:
1. It is inconsistent. In 'from A import *', 'A' is not drawn from the
current namespace, but from the external "namespace" of all modules that can
be imported from the current package.
2. It is ambiguous. If there exists a module called 'self', how is the
above statement to behave?
Incidentally, while 'from A import *' in a function works, it does not
behave correctly as of version 2.0. In particular, the following function
fails to behave as expected:
def f():
global path
from sys import *
print path
The problem goes away if I either remove 'global path' or replace the
'import *' with 'import path'. I'm guessing it took a really ugly hack to
get this to work at all, given how local variables are normally addressed,
and the hack is not entirely reliable.
--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list