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

noob questions

I'm new to python and I seem to get different behavior depending on...
well who knows what. Here's my question concerning importation of
packages/modules.

I want to use scipy. So at the prompt (using iPython, installed with
Enthought edition on Windows XP) I type:

ln [1]: from scipy import *

Now, I know integrate is a package this is in scipy. I want to use
the ode class/module that's in integrate. So I type:

ln [2]: from integrate import *

And I'm told

ImportError: No module named integrate

In order to get access to the ode class, I end up having to type:

ln [3]: from scipy.integrate import *

Then it works. Will someone explain to me what I'm misunderstanding?
I don't understand why after importing everything in scipy (which
includes integrate), I was told there was no module named integrate.
What gives? I there are sevarl functions (modules) that I want to use
that are a few levels down from the root package, what's the most
economical method of importing them?

Any clarification would be appreciated.

trevis

Apr 24 '07 #1
2 1926
T.Crane wrote:
I'm new to python and I seem to get different behavior depending on...
well who knows what. Here's my question concerning importation of
packages/modules.

I want to use scipy. So at the prompt (using iPython, installed with
Enthought edition on Windows XP) I type:

ln [1]: from scipy import *

Now, I know integrate is a package this is in scipy. I want to use
the ode class/module that's in integrate. So I type:

ln [2]: from integrate import *

And I'm told

ImportError: No module named integrate

In order to get access to the ode class, I end up having to type:

ln [3]: from scipy.integrate import *

Then it works. Will someone explain to me what I'm misunderstanding?
I don't understand why after importing everything in scipy (which
includes integrate), I was told there was no module named integrate.
What gives? I there are sevarl functions (modules) that I want to use
that are a few levels down from the root package, what's the most
economical method of importing them?

Any clarification would be appreciated.
Remember that scipy is a *package*. So when you say you have "imported
everything in scipy" that's not necessarily the case. You have imported
the scipy package, which has run the __init__.py in the package's base
directory. This doesn't necessarily do anything for scipy.integrate.

The statement

from integrate import *

tells the interpreter to search its sys.path looking for a module or
package called integrate. Just having imported scipy doesn't change
sys.path to put subdirectories of the scipy package's base directory
onto the path.

from scipy.integrate import *

however, tells the interpreter to look for a module or package *inside a
module or package called scipy* that can be found in one of the
directories on sys.path. Since the first import worked, and because
scipy is a package not just a plain module, this correctly locates the
integrate module (or package).

By the way, be careful with those from xxx import * statements. If scipy
is specifically designed to support such usage then you should be OK,
but in general this can "pollute" your namespace by bringing in all the
names defined in the imported package or module within your local
namespace. This might overwrite bindings you have already made within
that namespace. Just a point to watch.

regards
Steve
--
Steve Holden +1 571 484 6266 +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

Apr 24 '07 #2
T.Crane wrote:
I'm new to python and I seem to get different behavior depending on...
well who knows what. Here's my question concerning importation of
packages/modules.

I want to use scipy. So at the prompt (using iPython, installed with
Enthought edition on Windows XP) I type:

ln [1]: from scipy import *

Now, I know integrate is a package this is in scipy. I want to use
the ode class/module that's in integrate. So I type:

ln [2]: from integrate import *

And I'm told

ImportError: No module named integrate

In order to get access to the ode class, I end up having to type:

ln [3]: from scipy.integrate import *

Then it works. Will someone explain to me what I'm misunderstanding?
I don't understand why after importing everything in scipy (which
includes integrate), I was told there was no module named integrate.
What gives? I there are sevarl functions (modules) that I want to use
that are a few levels down from the root package, what's the most
economical method of importing them?
Everything Steve Holden said is correct. I'll just add that we do have a
function that will load all of the subpackages.

import scipy
scipy.pkgload()
from scipy import *

We don't load all of the subpackages by default because we have a lot of
extension modules that link to largish libraries. Loading all of them all of the
time takes substantial amounts of time.

Also, I don't recommend using either pkgload or "from scipy import *" in code.
However, from the interactive prompt, feel free. That is precisely what these
features were designed for.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Apr 24 '07 #3

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

Similar topics

6
by: administrata | last post by:
Hi! I'm programming maths programs. And I got some questions about mathematical signs. 1. Inputing suqare like a * a, It's too long when I do time-consuming things. Can it be simplified? 2....
7
by: administrata | last post by:
Is it possible? I tried... I = "John" print \ """ I used to love pizza"""
3
by: Rob Allen | last post by:
Hey fellas I am a web designer/developer with little in the way of formal training. I took some lower level programming courses to familiarize myself with structured programming and then taught...
8
by: Ivan Shevanski | last post by:
Alright heres another noob question for everyone. Alright, say I have a menu like this. print "1. . .Start" print "2. . .End" choice1 = raw_input("> ") and then I had this to determine what...
2
by: Dan McCollick | last post by:
Hi All, Noob question that I can not seem to figure out: I am trying to implement a screenscraper to pull data from two seperate websites, here is some test code so far: public static void...
0
by: webmaster | last post by:
I've been playing around with asp.net 2.0/vs.net 2005/C# 2005 - I had a few noob questions. 1. Is there a setting that sets all current and future controls on a page to position absolutely...
0
by: webmaster | last post by:
I've been playing around with asp.net 2.0/vs.net 2005/C# 2005 - I had a few noob questions. 1. Is there a setting that sets all current and future controls on a page to position absolutely...
5
by: Omar | last post by:
Hi all...this is a good group so I'm sure you'll tolerate some more noobish questions... 1) I'm also learning to program flash movies while I learn to do python. How can one implement flash...
4
by: jobs | last post by:
Three noob questions. Please help. 1. Is there a way to have arguments on subroutine that are optional? 2. Say I need to convert datetime to string..in this format : 2006-09-07...
5
by: Milan Krejci | last post by:
the thing is that descentant branches i dont want to expand do expand. $id variable contains an array of branches i want the program to go through (alcohol's id -beer id etc) function...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.