importing over network

  • Thread starter =?ISO-8859-2?Q?Bo=B9tjan_Jerko?=
  • Start date
?

=?ISO-8859-2?Q?Bo=B9tjan_Jerko?=

Is there a possibility to do import over the network?
I would like to put all my modules on a server and import them over the
network (internet or LAN).

B.
 
M

Michael Hudson

Boštjan Jerko said:
Is there a possibility to do import over the network? I would like
to put all my modules on a server and import them over the network
(internet or LAN).

Well, it's probably possible, but I'm not sure about easy or wise.
Something like NFS or samba is surely easier...

Cheers,
mwh
 
D

Diez B. Roggisch

I never worked with them, but there seems to be a mechanism named "import
hook" - google for it. That might be what you are looking for.
 
C

Cliff Wells

Is there a possibility to do import over the network?
I would like to put all my modules on a server and import them over the
network (internet or LAN).

You could use something like this (assuming the remote module is named
'foo.py' and has a function named 'foo'):

import sys, urllib, imp

remoteModules = {
'foo': 'http://www.IBetterKnowThisURLIsSecure.com/foo.py',
}

for name, url in remoteModules.items():
code = urllib.urlopen(url).read()
module = imp.new_module(name)
exec code in module.__dict__
globals()[name] = module

foo.foo()

This is pretty limited (doesn't support packages for one thing, and I'm
sure there's probably more restrictions). I'd personally take a look at
the ihooks module and see if you can use that instead.

You might also use some library that can pull down entire web sites
(such as HarvestMan) to pull the modules or packages locally and then
just use __import__ to import them. This would also give you some
caching abilities.

Regards,
Cliff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top