Writeing new files
Joal Heagney
s713221 at student.gu.edu.au
Sun Sep 2 21:02:37 EDT 2001
Maan Hamze wrote:
>
> "eber kain" <eberkain at earthlink.net> wrote in message
> news:b5f84cf8.0108311646.1ddf1f98 at posting.google.com...
> > you lost me, whats dir() do, and how do i use it.
> >
> >>> import os
> >>> dir(os)
> ['F_OK', 'O_APPEND', 'O_BINARY', 'O_CREAT', 'O_EXCL', 'O_RDONLY', 'O_RDWR',
> 'O_TEXT', 'O_TRUNC', 'O_WRONLY', 'P_DETACH', 'P_NOWAIT', 'P_NOWAITO',
> 'P_OVERLAY', 'P_WAIT', 'R_OK', 'TMP_MAX', 'UserDict', 'W_OK', 'X_OK',
> '_Environ', '__all__', '__builtins__', '__doc__', '__file__', '__name__',
> '_execvpe', '_exists', '_exit', '_get_exports_list', '_notfound', 'abort',
> 'access', 'altsep', 'chdir', 'chmod', 'close', 'curdir', 'defpath', 'dup',
> 'dup2', 'environ', 'error', 'execl', 'execle', 'execlp', 'execlpe', 'execv',
> 'execve', 'execvp', 'execvpe', 'fdopen', 'fstat', 'getcwd', 'getenv',
> 'getpid', 'i', 'isatty', 'linesep', 'listdir', 'lseek', 'lstat', 'makedirs',
> 'mkdir', 'name', 'open', 'pardir', 'path', 'pathsep', 'pipe', 'popen',
> 'popen2', 'popen3', 'popen4', 'putenv', 'read', 'remove', 'removedirs',
> 'rename', 'renames', 'rmdir', 'sep', 'spawnl', 'spawnle', 'spawnv',
> 'spawnve', 'startfile', 'stat', 'strerror', 'sys', 'system', 'times',
> 'umask', 'unlink', 'utime', 'write']
> >>>
> That is what dir() do :) A 'directory' of a module.
>
Also works on non-module objects
>>> class test:
... def __init__(self,*args, **kargs):
... self.args = args
... self.kargs = kargs
... def print_args(self):
... print self.args
... def print_kargs(self):
... print self.kargs
...
>>> a = test()
>>> dir(test)
['__doc__', '__init__', '__module__', 'print_args', 'print_kargs']
>>> dir(a)
['args', 'kargs']
>>> a.print_args()
()
>>> b = 'a string'
>>> dir(b)
['capitalize', 'center', 'count', 'encode', 'endswith', 'expandtabs',
'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace',
'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace',
'rfind', 'rindex', 'rjust', 'rstrip', 'split', 'splitlines',
'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper']
>>> b.upper()
'A STRING'
>>> b.split()
['a', 'string']
>>> b.capitalize()
'A string'
You may also be interested in pydoc
>>> import pydoc
>>> pydoc.help()
Welcome to Python 2.1! This is the online help utility.
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://www.python.org/doc/tut/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".
To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics". Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given
word
such as "spam", type "modules spam".
help> modules pydoc
Here is a list of matching modules. Enter any module name to get more
help.
pydoc - Generate Python documentation in HTML or text for interactive
use.
help> pydoc
(Opens up a line viewer)
Help on module pydoc:
NAME
pydoc - Generate Python documentation in HTML or text for
interactive use.
FILE
/usr/lib/python2.1/pydoc.py
DESCRIPTION
In the Python interpreter, do "from pydoc import help" to provide
online
help. Calling help(thing) on a Python object documents the object.
Or, at the shell command line outside of Python:
Run "pydoc <name>" to show documentation on something. <name> may
be
the name of a function, module, package, or a dotted reference to a
class or function within a module or module in a package. If the
argument contains a path segment delimiter (e.g. slash on Unix,
backslash on Windows) it is treated as the path to a Python source
file.
Run "pydoc -k <keyword>" to search for a keyword in the synopsis
lines
of all available modules.
Run "pydoc -p <port>" to start an HTTP server on a given port on the
local machine to generate documentation web pages.
For platforms without a command line, "pydoc -g" starts the HTTP
server
and also pops up a little window for controlling it.
Run "pydoc -w <name>" to write out the HTML documentation for a
module
to a file named "<name>.html".
CLASSES
Doc
HTMLDoc
TextDoc
exceptions.Exception
ErrorDuringImport
Helper
repr.Repr
HTMLRepr
TextRepr
Scanner
ModuleScanner
class Doc
|
| docclass = fail(self, object, name=None, *args)
|
lines 1-49
(This is as much as I could cut out of the viewer. q to exit)
help> q
You're now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)". Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.
>>>
(Actually, since I imported pydoc as a whole module, you have to type
pydoc.help(object). )
--
Joal Heagney is: _____ _____
/\ _ __ __ _ | | _ ___ |
/__\|\ || ||__ |\ || |___|/_\|___] |
/ \ \_||__ ||___| \_|! | | \ \ !
More information about the Python-list
mailing list