473,796 Members | 2,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to reload local namespace definitions in the python interpreter?

Hi,

I am a beginner using the python interpreter. To reduce typing effort,
I created a module called "aliases.py " containing some aliases for
objects I commonly use like -

aliases.py :
import filecmp, os, commands

op = os.path
go = commands.getout put
dc = filecmp.dircmp
p1 = '/mnt/usbkey/flash/'
p2 = '/mnt/fat32/myfiles/flash/'

When I start up the interpreter, I can simply type -

from aliases import *

This works fine, but each time I change any of the definitions in
aliases.py, I
have to restart the interpreter and type "from aliases import *"
again. Is there any way to reload these definitions without restarting
the interpreter?

-Slath

Jul 18 '05 #1
4 1802
te***********@y ahoo.co.uk wrote:
Hi,

I am a beginner using the python interpreter. To reduce typing effort,
I created a module called "aliases.py " containing some aliases for
objects I commonly use like -

aliases.py :
import filecmp, os, commands

op = os.path
go = commands.getout put
dc = filecmp.dircmp
p1 = '/mnt/usbkey/flash/'
p2 = '/mnt/fat32/myfiles/flash/'

When I start up the interpreter, I can simply type -

from aliases import *

This works fine, but each time I change any of the definitions in
aliases.py, I
have to restart the interpreter and type "from aliases import *"
again. Is there any way to reload these definitions without restarting
the interpreter?

-Slath


reload(aliases)

See: http://www.python.org/doc/2.4.1/lib/built-in-funcs.html

By the way, are you aware of the import ... as ... idiom?
e.g. import os.path as op

--
Website: www DOT jarmania FULLSTOP com
Jul 18 '05 #2
Tim Jarman wrote:
te***********@y ahoo.co.uk wrote:

Hi,

I am a beginner using the python interpreter. To reduce typing effort,
I created a module called "aliases.py " containing some aliases for
objects I commonly use like -

aliases.py :
import filecmp, os, commands

op = os.path
go = commands.getout put
dc = filecmp.dircmp
p1 = '/mnt/usbkey/flash/'
p2 = '/mnt/fat32/myfiles/flash/'

When I start up the interpreter, I can simply type -

from aliases import *

This works fine, but each time I change any of the definitions in
aliases.py, I
have to restart the interpreter and type "from aliases import *"
again. Is there any way to reload these definitions without restarting
the interpreter?

-Slath

reload(aliases)

Unfortunately a simple reload of the module won't result in the required
changes to the local namespace:

$ cat test87.py
val = 33
from test87 import *
print val 33 val = 42
reload(test87) <module 'test87' from 'test87.pyc'> print val 42

See: http://www.python.org/doc/2.4.1/lib/built-in-funcs.html

By the way, are you aware of the import ... as ... idiom?
e.g. import os.path as op


This would, of course, require the user to qualify the names by
prefixing them with "op.".

regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/

Jul 18 '05 #3
On Apr 4, 2005 11:10 AM, Steve Holden <st***@holdenwe b.com> wrote:
Tim Jarman wrote:
te***********@y ahoo.co.uk wrote:

Hi,

I am a beginner using the python interpreter. To reduce typing effort,
I created a module called "aliases.py " containing some aliases for
objects I commonly use like -

aliases.py :
import filecmp, os, commands

op = os.path
<snip> By the way, are you aware of the import ... as ... idiom?
e.g. import os.path as op


This would, of course, require the user to qualify the names by
prefixing them with "op.".


What the OP listed above requires that too.

Peace
Bill Mill
bill.mill at gmail.com
Jul 18 '05 #4
Bill Mill wrote:
On Apr 4, 2005 11:10 AM, Steve Holden <st***@holdenwe b.com> wrote:
Tim Jarman wrote:
te********** *@yahoo.co.uk wrote:

Hi,

I am a beginner using the python interpreter. To reduce typing effort,
I created a module called "aliases.py " containing some aliases for
objects I commonly use like -

aliases.p y :
import filecmp, os, commands

op = os.path
<snip>
By the way, are you aware of the import ... as ... idiom?
e.g. import os.path as op


This would, of course, require the user to qualify the names by
prefixing them with "op.".

What the OP listed above requires that too.

I believe the OP was suggesting

from aliases import *

which specifically loads the names in the module (or those specified in
module.__all__) into the importing namespace for use without qualification.

regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Jul 18 '05 #5

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

Similar topics

66
3915
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
1811
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...
47
3651
by: Andrey Tatarinov | last post by:
Hi. It would be great to be able to reverse usage/definition parts in haskell-way with "where" keyword. Since Python 3 would miss lambda, that would be extremly useful for creating readable sources. Usage could be something like: >>> res = where: >>> def f(x):
4
4669
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))
1
1270
by: Kiran | last post by:
Hi all, I am trying to get the following to work, but cant seem to do it the way i want to. ok, so I come into python and do the following: then, i have a file called test.py in which i say: print x Now, after having defined x =1 in the python interpreter, i come in and
12
1820
by: reubendb | last post by:
Hello, I am new to Python. I have the following question / problem. I have a visualization software with command-line interface (CLI), which essentially is a Python (v. 2.5) interpreter with functions added to the global namespace. I would like to keep my own functions in a separate module and then import that module to the main script (that will be executed using the CLI interpreter). The problem is, I cannot access the functions in the...
3
1553
by: Stef Mientki | last post by:
hello, I've a graphical application (wxPython), where the code in the main GUI loop is given below. 1 JAL_Loaded = False 2 while len(App_Running) 0: 3 if JALsPy_globals.State == SS_Run: 4 try:
2
3688
by: gbin,Zhou | last post by:
Hi,all. I see from "http://docs.python.org/tut/node11.html" that "Name spaces are created at different moments and have different lifetimes. The namespace containing the built-in names is created when the Python interpreter starts up, and is never deleted. The global namespace for a module is created when the module definition is read in; normally, module namespaces also last until the interpreter quits." So can I "delete" the namespace...
0
1511
by: Alan Baljeu | last post by:
Alan Baljeu http://www.collaborative-systems.org Intelligent software that works _with_ you. ----- Forwarded Message ---- From: Alan Baljeu <alanbaljeu@yahoo.com> To: Mike Driscoll <kyosohma@gmail.com> Sent: Friday, November 14, 2008 2:06:26 PM
0
9530
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
10459
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
10236
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...
0
10017
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...
0
9055
agi2029
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...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
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...
0
5577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.