why import, reload, import again?

B

beliavsky

Near the beginning of file test_matrix.py from scipy are the lines

import scipy.base
reload(scipy.base)
from scipy.base import *
del sys.path[0]

Could someone please explain why the first two lines were included? A
similar script I wrote works fine without them. Also, what is the
purpose of the "del" line? (I understand the mechanics of what "del"
does.) The scipy developers are skilled Python programmers, so I am
trying to understand the idioms used in their codes.
 
P

Peter Hansen

Near the beginning of file test_matrix.py from scipy are the lines

import scipy.base
reload(scipy.base)
from scipy.base import *
del sys.path[0]

Could someone please explain why the first two lines were included? A
similar script I wrote works fine without them.

It would very likely be solely for testing purposes, and only because
test_matrix.py could be run (after importing it, as opposed to via
os.system) from another script which also runs other tests.

Doing the above has the effect of ensuring that scipy.base is reloaded
prior to the "from scipy.base import *" line. Without the first two,
the test_matrix.py script could be getting various globals from
scipy.base which were modified during a previous test. (This smells a
bit... tests shouldn't be polluting scipy.base, and scipy.base probably
shouldn't be doing anything magic that requires that reload in the first
place, but there may be good reasons for it.)

(I recognize that "idiom" from having had to do it at the interactive
prompt with a module where I was doing "from xxx import *".)
> Also, what is the
purpose of the "del" line? (I understand the mechanics of what "del"
does.) The scipy developers are skilled Python programmers, so I am
trying to understand the idioms used in their codes.

I can only guess it's something similar... actually, I won't guess here
as the only guesses I can think of would invalidate my theory above. :)

-Peter
 
R

Robert Kern

Near the beginning of file test_matrix.py from scipy are the lines

import scipy.base
reload(scipy.base)
from scipy.base import *
del sys.path[0]

Could someone please explain why the first two lines were included? A
similar script I wrote works fine without them. Also, what is the
purpose of the "del" line? (I understand the mechanics of what "del"
does.) The scipy developers are skilled Python programmers, so I am
trying to understand the idioms used in their codes.

Pearu probably knows. You should ask on the scipy list as this is almost
certainly a holdover from the older version of scipy.

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top