Does anyone know of a way to dynamically reload all the imported modules of a
client module?
I'm writing a program that I have broken down into quite a few submodules, and
the 'configuration' is done with modules too. As I am developing the app, I
need to test bits and pieces here and there. This is what I currently do:
In each module, I have a section, just after the main imports like so:
-----------8<-----------
# normal imports:
from ooby import squibble,dibble
import dooby
import doo
# reloads for debugging
import ooby # create a reference to ooby so we can reload it
reload(ooby)
reload(dooby)
reload(doo)
# main module code begins...
-----------8<-----------
The debugging imports of course will be dropped when the program is stable.
I also often find myself doing similar stuff from the command-line, like:
reload(ooby.ooj ar); reload(ooby.dib ble); reload(ooby); ooby.somefunc(. ....)
I just wondered if anyone had develped a better 'spell' or even a small script
that uses some clever intorspecton hack, before I go and start trying to
reinvent the wheel...
-andyj 2 2465
I've wondered about the same problem and considered that as a solution, but
never tested it. I assume that *wouldn't* rebind all of the imports that
have already happened.. ie, I think the references to the old copies of
the modules would hang around even though new ones have been imported.
Regardless, the scoping doesn't work so an attempt to reload the embedded
module assumes it is available in local scope and fails. Again, that would
lead me to believe my first statement is true, but when I tested just now,
I got no further than the scoping problem...
I've been intended to write something that will take a module name and
rebind it in all namespaces that have it currently, but haven't got around
to it. If I ever do, I'll post it here :)
Greg
Martin v. Löwis wrote: Andy Jewell <an**@wild-flower.co.uk> writes:
Does anyone know of a way to dynamically reload all the imported modules of a client module?
You could iterate over sys.modules and invoke reload for all of them.
Regards, Martin
Greg Fortune <li***@gregfort une.com> writes: I've wondered about the same problem and considered that as a solution, but never tested it. I assume that *wouldn't* rebind all of the imports that have already happened.. ie, I think the references to the old copies of the modules would hang around even though new ones have been imported.
Depends on the import. For
import foo
the reload would take effect, as, on reload, the module object stays,
its dictionary stays, and it is just the dictionary contents that is
recreated.
For
from foo import bar
you still have the old value of bar after reloading.
Regardless, the scoping doesn't work so an attempt to reload the embedded module assumes it is available in local scope and fails. Again, that would lead me to believe my first statement is true, but when I tested just now, I got no further than the scoping problem...
What scoping problem?
I've been intended to write something that will take a module name and rebind it in all namespaces that have it currently, but haven't got around to it. If I ever do, I'll post it here :)
Just ask Guido to borrow you the time machine - this has already been
done.
Regards,
Martin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: OKB (not okblacke) |
last post by:
I'm fooling around with some MUD server code, and I want to add a
"reload" command that will let MUD wizards reload the server modules,
so that changes to the MUD parser and such can be effected without
having to shut down and restart the server.
Now, what I want to do at the top of my main module, instead of
just "import somemodule", is something like this:
try:
reload(somemodule)
|
by: aurora |
last post by:
I am looking for a way for reloading updated modules in a long running
server. I'm not too concerned about cascaded reload or objects already
created. Just need to reload module xxx if the corresponding xxx.py is
updated.
I found something useful in module.__file__. Would it work if I use it to
generate filenames xxx.py xxx.pyc and then compare their mtime? I'm not
too sure about the mechanism of generation of .pyc file. Would it be too...
|
by: Lowell Kirsh |
last post by:
I have a driver module as well as several other modules. I am running
the driver interactively from emacs - that is, I don't restart python on
each run. I want to work it such that every time a modify the source for
one of the non-driver modules and re-run the driver, the other modules
will be reloaded. I have the following at the top of my driver module:
import dbtest, util
for module in :
if module in sys.modules.keys():...
|
by: Tim N. van der Leeuw |
last post by:
Hi,
The following might be documented somewhere, but it hit me unexpectedly
and I couldn't exactly find this in the manual either.
Problem is, that I cannot use augmented assignment operators in a
nested scope, on variables from the outer scope:
PythonWin 2.4.3 (#69, Mar 29 2006, 17:35:34) on win32.
Portions Copyright 1994-2004 Mark Hammond (mhammond@skippinet.com.au) -
|
by: Seymour |
last post by:
I created a module with the DictAdder subclass as follows:
class DictAdder(Adder):
def add(self, x, y):
new={}
for k in x.keys(): new=x
for k in y.keys(): new=y
return new
At the interactive prompt I then said: from Adder import *
| |
by: aine_canby |
last post by:
I'm using python.exe to execute my modules. I have a music.py module
which contains my classes and a main.py module which uses these
classes. In python.exe, I call "import main" to execute my program. The
problem is that I have to close python and reopen it everytime i change
music.py or main.py. What should I be doing.
Thanks,
Aine.
|
by: tsuraan |
last post by:
Supposing that I have a directory tree like so:
a/
__init__.py
b/
__init__.py
c.py
and b.py has some method (let's call it d) within it. I can, from python, do:
|
by: lukasz.f24 |
last post by:
Hello,
I came across annoying problem during my fun with mod_python. I turned
out that mod_python load package only onca and don't care about any
changes to it. Obviously it makes sense on production server but
during development is more then annoying. I find a way to reload my
module:
m = apache.import_module(name)
reload(m)
|
by: Tlis |
last post by:
I am using a software system with an embedded Python interpreter
(version 2.3) for scripting. The KcsPoint2D.py module contains a
Point2D class with the following method:
def SetFromMidpoint(self, p1, p2):
if not isinstance(p1, Point2D) or not isinstance(p2, Point2D):
raise TypeError, 'some error message'
---
The problem is that after I launch my script once, and then use the
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |