473,395 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.getoutput
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 1786
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.py :
import filecmp, os, commands

op = os.path
go = commands.getoutput
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***********@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.py :
import filecmp, os, commands

op = os.path
go = commands.getoutput
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***@holdenweb.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.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***@holdenweb.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.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.

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
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. ...
4
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...
47
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...
4
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...
1
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:...
12
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...
3
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...
2
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.