Personal tools
You are here: Home CDAT Tips and Tricks Python Tips Inquiries into Modules.
Document Actions

Inquiries into Modules.

by Renata McCoy last modified 2007-05-08 10:48

Goal: Learn how to check what's inside a module.

 
The built-in function dir() can be used to find out which names a module defines. It returns a sorted list of strings:
# import 'time' module

# see what functions are defined in the 'time' module
dir(time)
['__doc__', '__file__', '__name__', 'accept2dyear',
'altzone', 'asctime', 'clock', 'ctime', 'daylight',
'gmtime', 'localtime', 'mktime', 'sleep', 'strftime',
'strptime', 'struct_time', 'time', 'timezone', 'tzname',
'tzset']

# whithout arguments, 'dir()' lists the names: variables,
# modules and functions you have defined currently
dir()
['__builtins__', '__doc__', '__file__', '__name__',
'readline', 'rlcompleter', 'time']

You can see if there is an internal documentaion by looking at .__doc__

# check the documentation about the ctime() function
print time.ctime.__doc__
ctime(seconds) -> string

Convert a time in seconds since the Epoch to a string in local time.
This is equivalent to asctime(localtime(seconds)). When the time
tuple is
not present, current time as returned by localtime() is used.

# to see the whole documentation on time() module, type
print time.__doc__
This module provides various functions to manipulate time values.
...

Variables:

timezone -- difference in seconds between UTC and local standard time
altzone -- difference in seconds between UTC and local DST time
daylight -- whether local time should reflect DST
tzname -- tuple of (standard time zone name, DST time zone name)

Functions:

time() -- return current time in seconds since the Epoch as a float
clock() -- return CPU time since process start as a float
sleep() -- delay for a number of seconds given as a float
gmtime() -- convert seconds since Epoch to UTC tuple
localtime() -- convert seconds since Epoch to local time tuple
asctime() -- convert time tuple to string
ctime() -- convert time in seconds to string
mktime() -- convert local time tuple to seconds since Epoch
strftime() -- convert time tuple to string according to format specification
strptime() -- parse string to time tuple according to format specification
tzset() -- change the local timezone


You can also get help woth through the help() function

# use help(..) to get more info on the module
help(time)
Help on module time:

NAME
time - This module provides various functions to manipulate time values.

FILE
/home/mccoy20/utils/cdat/lib/python2.4/lib-dynload/time.so

MODULE DOCS
http://www.python.org/doc/current/lib/module-time.html

DESCRIPTION
There are two standard representations of time. One is the number
of seconds since the Epoch, in UTC (a.k.a. GMT). It may be an integer
or a floating point number (to represent fractions of seconds).
The Epoch is system-defined; on Unix, it is generally January 1st, 1970.
The actual value can be retrieved by calling gmtime(0).

.....




Powered by Plone