PDA

View Full Version : [SOLVED] Python Imported functions


kjohansen
September 6th, 2008, 08:51 PM
I did:


import scipy.stats
a=[2,3,5,2,3,2,3]
scipy.stats.mean(a)


Is there a way to not have to use the full path for the mean function?

That is can I import scipy.stats and then just do:

mean(a)

imdano
September 6th, 2008, 09:08 PM
Yep from scipy.stats import mean

kjohansen
September 6th, 2008, 09:11 PM
what if I want all the functions within the scipy.stats package to be available like that, is that possible?

kjohansen
September 6th, 2008, 09:12 PM
nevermind.

from scipy.stats import *

OutOfReach
September 6th, 2008, 09:14 PM
from MODULE_NAME import *

pmasiar
September 6th, 2008, 10:31 PM
what if I want all the functions within the scipy.stats package to be available like that, is that possible?

import * is dangerous practice: you may import name clashing with your own name, and strange things might happen. Much safer to import name by name (you can list them, separated by comma), to see exactly what is coning from where. Easier to debug later, too.