473,327 Members | 2,055 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,327 software developers and data experts.

Delete a function

gtb

After a function has been imported to a shell how may it be deleted so
that after editing it can reloaded anew?

thanx,

gtb

Mar 21 '07 #1
6 2175
gtb wrote:
After a function has been imported to a shell how may it be deleted so
that after editing it can reloaded anew?
Use the built-in reload() function to reload the module that defines the
function.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Mar 21 '07 #2
gtb
On Mar 21, 11:37 am, Steve Holden <s...@holdenweb.comwrote:
gtb wrote:
After a function has been imported to a shell how may it be deleted so
that after editing it can reloaded anew?

Use the built-in reload() function to reload the module that defines the
function.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com
Thanks, tried that now and get nameError: with the following.

import sys
sys.path.append("c:\maxq\testScripts")

from CompactTest import CompactTest
from compactLogin import dvlogin

reload(compactLogin)

Mar 21 '07 #3
gtb wrote:
On Mar 21, 11:37 am, Steve Holden <s...@holdenweb.comwrote:
>gtb wrote:
After a function has been imported to a shell how may it be deleted so
that after editing it can reloaded anew?

Use the built-in reload() function to reload the module that defines the
function.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Thanks, tried that now and get nameError: with the following.

import sys
sys.path.append("c:\maxq\testScripts")
That's an interesting directory name:
>>print "c:\maxq\testScripts"
c:\maxq estScripts

from CompactTest import CompactTest
from compactLogin import dvlogin
The above line puts dvlogin into the current namespace, not compactLogin;
therefore
reload(compactLogin)
compactLogin is undefined in the reload() call. You need

import compactLogin # still the old module because it's in the module cache
reload(compactLogin)
from compactLogin import dvlogin # update the function
del compactLogin # optional

Peter

Mar 21 '07 #4
gtb wrote:
On Mar 21, 11:37 am, Steve Holden <s...@holdenweb.comwrote:
>gtb wrote:
>>After a function has been imported to a shell how may it be deleted so
that after editing it can reloaded anew?
Use the built-in reload() function to reload the module that defines the
function.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Thanks, tried that now and get nameError: with the following.

import sys
sys.path.append("c:\maxq\testScripts")

from CompactTest import CompactTest
from compactLogin import dvlogin

reload(compactLogin)
The local compactLogin isn't being bound to the module because of the
import form you are using.

Here's meta1.py:

$ more meta1.py
class MyMeta(type):
...

class MyClass:
__metaclass__ = MyMeta

Now see what happens when I import the MyMeta class from it:
>>from meta1 import MyMeta
import sys
sys.modules['meta1']
<module 'meta1' from 'meta1.py'>
>>reload(meta1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'meta1' is not defined
>>reload(sys.modules['meta1'])
<module 'meta1' from 'meta1.pyc'>
>>>
Note, however, that this reload() call does NOT re-bind the local
MyMeta, which still references the class defines in the original version
of the module. You'd be better off using

import compactLogin

and then setting

dvlogin = compactLogin.dvlogin

after the original import and each reload. Eventually you'll develop a
feel for how namespaces work in Python and you'll be able to take liberties.

Finally, note that there isn't much point doing the reload() unless the
content of the modue has actually changed!

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Mar 21 '07 #5
gtb schrieb:
On Mar 21, 11:37 am, Steve Holden <s...@holdenweb.comwrote:
>gtb wrote:
>>After a function has been imported to a shell how may it be deleted so
that after editing it can reloaded anew?
Use the built-in reload() function to reload the module that defines the
function.
Thanks, tried that now and get nameError: with the following.

import sys
sys.path.append("c:\maxq\testScripts")

from CompactTest import CompactTest
from compactLogin import dvlogin

reload(compactLogin)
you haven't imported compactLogin but dvlogin from the compactLogin
namespace. Try:

import compactLogin
....do something with compactLogin.dvlogin...

reload(compactLogin)

cheers
Paul

Mar 21 '07 #6
gtb
On Mar 21, 12:45 pm, paul <p...@subsignal.orgwrote:
gtb schrieb:On Mar 21, 11:37 am, Steve Holden <s...@holdenweb.comwrote:
gtb wrote:
After a function has been imported to a shell how may it be deleted so
that after editing it can reloaded anew?
Use the built-in reload() function to reload the module that defines the
function.
Thanks, tried that now and get nameError: with the following.
import sys
sys.path.append("c:\maxq\testScripts")
from CompactTest import CompactTest
from compactLogin import dvlogin
reload(compactLogin)

you haven't imported compactLogin but dvlogin from the compactLogin
namespace. Try:

import compactLogin
...do something with compactLogin.dvlogin...

reload(compactLogin)

cheers
Paul
~~~~~~~~~~~~~~~~
Eventually you'll develop a feel for how namespaces work in Python...
.... where " 0 < Eventually < Infinity " ;^)

Whoa, my brain is full, I'll glean it directly tho. Thanks all for
posting.

Mar 21 '07 #7

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

Similar topics

3
by: Asif Rahman | last post by:
Hi all! Please improve on the following code to make sure the record gets deleted only when the function returns false. Now I see the msgbox, but the record gets deleted no matter the user...
1
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
3
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. I am...
5
by: | last post by:
Hi all, I've been using C++ for quite a while now and I've come to the point where I need to overload new and delete inorder to track memory and probably some profiling stuff too. I know that...
1
by: Douglas Peterson | last post by:
class Allocator { public: virtual void * Alloc(size_t) = 0; virtual void * Free(void*) = 0; }; class Object { public:
5
by: wongjoekmeu | last post by:
Hiya all, I am trying to use function pointers. I know that usually if you use a pointer to an object, you have to release the memory at the end by calling the delete keyword. I was wondering if...
5
by: tom | last post by:
Hi, I'm overriding my operator new and operator delete for two classes, one inherited from the other, so I can use my own memory pool. A simplified version of what I have is below: class...
3
by: bluez | last post by:
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record. ...
24
by: biganthony via AccessMonster.com | last post by:
Hi, I have the following code to select a folder and then delete it. I keep getting a Path/File error on the line that deletes the actual folder. The line before that line deletes the files in...
11
by: Ed Dror | last post by:
Hi there, I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro. I have a Price page (my website require login) with GridView with the following columns PriceID, Amount, Approved,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.