[Tutor] about import statement

Alan Gauld alan.gauld at btinternet.com
Mon Jan 10 19:28:16 CET 2011


"arun kumar" <arunkumar413 at gmail.com> wrote

> I have some doubts in python. When we write programs,we write some
> import statements at the beginning of the code. how to know that we
> should import something. 

Trial and error, experience and mainly reading the documentation.
You try to do something and there is no obvious direct solution in
the basic Python built-in commands and functions, so we go to 
the module library to see if anything looks useful.

Then we use dir() and help() to find out what is in the module 
and how to use it. If nothing exists in the library then we try 
Google and perhaps install a third party package.

> How do we know that certain classes are in particular module?

dir(), help() and reading the documents.

Sorry, there are no easier answers, but that kind of research 
is one of the keys to programming. And sometimes you will 
probably write code that could have been done via a module
but you just didn't know it existed. I've done that lots of times!

Reading this list is a good way to discover some of the more 
obscure but useful modules available.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list