How to reload local namespace definitions in the python interpreter?

T

test1dellboy3

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
 
T

Tim Jarman

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
 
B

Bill Mill

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
 
S

Steve Holden

Bill said:
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
 

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,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top