473,782 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ipython shortcut to reload modules

Hey!

I'm using ipython as my python shell and often run scripts with the
magic command %run:

In [1]: %run script.py

If modules are loaded within the script these are not reloaded when I
rerun the script. Hence, when I changed some of the modules loaded, I
have to call

In [2]: reload(module1)
Out [2]: <module 'module1' from ....
In [3]: reload(module2)
Out [3]: <module 'module2' from ...
In [4]: %run script.py

Is there a shortshut to reload the modules automatically before
rerunning the script?

In case of names imported from modules into the shell environment I
have to reload and re-import in order to have the changes available:

In [5]: from module1 import *
In [6]: reload(module1)
In [7]: from module1 import *

Is there a shortcut to force a reload of loaded modules and re-
defining the names loaded with from....import. ..?

Thanks! Bernhard

Feb 19 '07 #1
1 13391
be************@ gmail.com wrote:
Hey!

I'm using ipython as my python shell and often run scripts with the
magic command %run:

In [1]: %run script.py

If modules are loaded within the script these are not reloaded when I
rerun the script. Hence, when I changed some of the modules loaded, I
have to call

In [2]: reload(module1)
Out [2]: <module 'module1' from ....
In [3]: reload(module2)
Out [3]: <module 'module2' from ...
In [4]: %run script.py

Is there a shortshut to reload the modules automatically before
rerunning the script?
No. But if you're including them in the script, they won't be reloaded
because they're already present in the namespace. If you do %reset
before your %run, it'll clear up the namespace, so your script's import
should work. Downside: its effectively the same as quitting out of
ipython, and restarting it. Other then that, I don't think you have much
choice.
Oh, if you use the %edit command to edit these files, it should reload
them when you're done editing.
-Jordan
Feb 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
3011
by: Christian Seberino | last post by:
I know IPython is another interpreter for Python and was wondering what people liked about it and if I should switch to it. If it is so good then why is it not part of the standard Python tarball? Chris
66
3908
by: Ellinghaus, Lance | last post by:
> > Other surprises: Deprecating reload() >Reload doesn't work the way most people think >it does: if you've got any references to the old module, >they stay around. They aren't replaced. >It was a good idea, but the implementation simply >doesn't do what the idea promises. I agree that it does not really work as most people think it does, but how
4
1810
by: David MacQuigg | last post by:
I'm going to be teaching EEs some basic Python using the first few chapters of Learning Python, 2nd ed. by Mark Lutz. The discussion on Reloading Modules starting on page 266 is confusing and I believe incorrect. On page 266 it says that a reload "changes the existing module object in place." That's a little vague, but on page 267 it says "every reference to a module object anywhere in your program is automatically affected by a...
1
1515
by: Ismael Herrera | last post by:
Hi,i wonder if there is an editor or ide that has similar dinamic instrospection features as ipython? ,since i have failed to find one, i spend more time coding in ipython than in my editor. Well the feature i need the most is tab introspection since python has so many libraries and functions that is imposible to remember all of them.For example when i type urllib2.<tab> i get: urllib2.AbstractBasicAuthHandler urllib2.__class__...
3
1566
by: Dave Merrill | last post by:
Hi, I'm new to python, and ipython, but not to programming, having trouble getting ipython installed on windows 2000, python 233. Any help would be much appreciated; I'm sure I'm being some basic flavor of dense... First downloaded and installed PythonWin, readline and ctypes. They're all pretty clearly here and working, because I can run PythonWin, and from there, importing readline and ctypes works. Then downloaded ipython-0.6.6.zip...
4
4665
by: Lonnie Princehouse | last post by:
So, it turns out that reload() fails if the module being reloaded isn't in sys.path. Maybe it could fall back to module.__file__ if the module isn't found in sys.path?? .... or reload could just take an optional path parameter... Or perhaps I'm the only one who thinks this is silly: >>> my_module = imp.load_module(module_name, *imp.find_module(module_name,path))
0
1284
by: Fernando Perez | last post by:
Hi all, The IPython team is happy to release version 0.7.2, with a lot of new enhancements, as well as many bug fixes. We hope you all enjoy it, and please report any problems as usual. WHAT is IPython? ----------------
2
4787
by: Daniel Mark | last post by:
Hello all: I installed IPython on my XP machine today and find that my sys.path has been changed as follows:
0
1905
by: Rafe | last post by:
Hi, This seems to be an old question, and I've read back a bit, but rather than assume the answer is "you can't do that", I'd thought I'd post my version of the question along with a reproducible error to illustrate my confusion. My problem is that I'm using Python inside XSI (a 3D graphics application). If I want to restart Python, I have to restart XSI. This is no small amount of time wasted.
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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,...
0
10308
Oralloy
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...
0
10143
jinu1996
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...
1
10076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9939
tracyyun
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...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2870
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.