reloading the module imported as 'from ... import ...'

AlF spamgrinder.trylater at ggmail.com
Mon Aug 10 01:48:31 EDT 2009


Steven D'Aprano wrote:
> On Sun, 09 Aug 2009 20:43:41 -0700, AlF wrote:
> 
>> Hi,
>>
>> what is the best way to reload the module imported using 'from ...
>> import ...'
> 
> 
> Have you tried "from ... import ..." again?
> 

I have not because of an assumption that "import" imports the module 
just once. In fact this still works that way:

here is a terminal 1:

$ cat > a.py
a=1
$ cat > a.py
a=2
$


and terminal 2:

 >>> from a import a
 >>> a
1
 >>> a
1
 >>> from a import a
 >>> a
1
 >>>

In spite of changing a.py in fly, the imported a is still 1





More information about the Python-list mailing list