Is this a valid use of 'import'?
fredrik at pythonware.com
Tue Jul 22 17:31:15 CEST 2008
Frank Millman wrote:
> I know that when a module is imported the first time, it is
> 'executed'. This normally entails setting up constants, classes,
> functions, etc, that you want to make available to the importer.
> In this particular case, when it is executed, it does a whole lot
> more. It reads in some parameters, establishes a socket connection,
> starts a thread, and starts monitoring the socket using select.select.
> It also exposes some functions that disguise the complexity of reading
> from and writing to the socket.
> This enables me to write a 'client' program that look like this -
> from Utils.client import *
> cust = getRecord(
> print cust
> As you can see, it makes writing a client program very easy.
> Are there any problems with this approach?
besides being fragile and not scalable and not thread-safe and
incompatible with introspection tools and utterly surprising for people
used to normal Python behaviour, and only marginally easier to write
from Utils.client import Client
c = Client()
cust = c.getRecord(
and some other problems that I cannot think of right now, you mean?
More information about the Python-list