deleting, then re-importing a class method

R

Robert P. J. Day

(once again, never ashamed to ask the dumb questions.)

still playing with python3, and testing whether i can
delete/unimport a specific method, then re-import it:
module(name[, doc])

Create a module object.
The name must be a string; the optional doc argument can have any
type.
ok, now that i've deleted just that member of "sys", can i re-import
it? i know this doesn't seem to work:

or is there an operator other than "import" that more represents a
full refresh of a class?

rday

p.s. no, i don't have a valid application of the above, i'm just
trying to break things.

--


========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page: http://crashcourse.ca
Twitter: http://twitter.com/rpjday
========================================================================
 
P

Peter Otten

Robert said:
(once again, never ashamed to ask the dumb questions.)

still playing with python3, and testing whether i can
delete/unimport a specific method, then re-import it:
module(name[, doc])

Create a module object.
The name must be a string; the optional doc argument can have any
type.
ok, now that i've deleted just that member of "sys", can i re-import
it? i know this doesn't seem to work:

Actually you haven't:
True


or is there an operator other than "import" that more represents a
full refresh of a class?
imp.reload()

rday

p.s. no, i don't have a valid application of the above, i'm just
trying to break things.

That is indeed likely to happen:

Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.False

So you have to two distinct walk() functions now. This becomes especially
nasty when

isinstance(obj, module.Class)

tests begin to fail because the module and the class was reloaded, but obj
is an instance of module.Class before the reload.

Peter
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top