LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-08-2005, 07:03 AM   #1
tuxfood
Member
 
Registered: Aug 2003
Location: kerala , India
Distribution: RH9 , FC1 ,
Posts: 141

Rep: Reputation: 15
Python doubt.... regarding reloading modules


hi..

I have just started to lean this incredible language .
So rite now i am learning about modules




So heres what i faced


I have a module which is in a file

Code:
     
   #functions.py


   def foo():
         print 1



   def foo1():  
        print 2


So i load the above module from my python shell

>>> import functions
>>>functions.foo()
1 //correct


BUt if i change the orginal functions.py to someelse
eg:

Code:
     
   #functions.py


   def foo():
         print 3


   def foo1():  
        print 2
and load the module again ,this is what happens

>>>import functions
>>>functions.foo()
1 ///and not 3

OK
The docs say that when a module is loaded the assignments inside it and the function definitions inside it ae only evaluated the first time it is loaded


So is there a way to come around this problem
 
Old 06-08-2005, 07:48 AM   #2
oneandoneis2
Senior Member
 
Registered: Nov 2003
Location: London, England
Distribution: Ubuntu
Posts: 1,460

Rep: Reputation: 46
I'm also only just starting to learn Python, but IIRC, for efficiency reasons it only reads from the file the first time you import.

You have to explicititly tell it to reload if you change a module, not just import it again, i.e. use "reload(functions)" rather than "import functions"

But that IS the opinion of somebody who's only up to chapter 6 in O'Reilly's "Learning Python", so I could well be utterly wrong

Last edited by oneandoneis2; 06-08-2005 at 07:56 AM.
 
Old 06-08-2005, 08:35 AM   #3
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
Quote:
Originally posted by oneandoneis2
I'm also only just starting to learn Python, but IIRC, for efficiency reasons it only reads from the file the first time you import.

You have to explicititly tell it to reload if you change a module, not just import it again, i.e. use "reload(functions)" rather than "import functions"

But that IS the opinion of somebody who's only up to chapter 6 in O'Reilly's "Learning Python", so I could well be utterly wrong
No you are utterly right:

>>> reload(functions)

is what you have to do.
 
Old 06-09-2005, 07:56 AM   #4
tuxfood
Member
 
Registered: Aug 2003
Location: kerala , India
Distribution: RH9 , FC1 ,
Posts: 141

Original Poster
Rep: Reputation: 15
hi...

thnks..

i accidently happened to find that out myself ..

as a learner

did u know that all built in functions and names are there in the module __builtin__

so just import __builtin__ and

do help(__builtin__) and u have information abt

module loading and reloading etc

In case u knew this ... maybe i just refreshed ur memory

anyways thnks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
listing python modules southsibling Programming 2 10-09-2005 12:53 AM
Reloading .bashrc tbartolucci Linux - Newbie 3 07-16-2004 09:22 AM
Reloading fstab EnigmaX Linux - Newbie 1 09-23-2003 10:35 AM
Python modules in Superkaramba wakeupbomb Linux - Software 12 08-03-2003 05:55 PM
Reloading Samba artman62 Linux - Networking 2 06-11-2002 07:25 PM


All times are GMT -5. The time now is 09:27 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration