html parser etc help
Jeremy Yallop
jeremy at jdyallop.freeserve.co.uk
Sat Jun 15 04:44:15 EDT 2002
* Xah Lee
| Thanks Jeremy Yallop for help. Some follow up questions...
|
| in the following code:
|
| import os
| def visit(arg, dirname, fnames):
| for file in fnames:
| if file.endswith('.html'):
| print file
| print arg
| os.path.walk('/export/home/xah/unixnotes/',visit,'---')
|
|
| * in the os.path.walk, what's the third argument for?
Here's what the interactive help says:
>>> import os
>>> help(os.path.walk)
Help on function walk in module posixpath:
walk(top, func, arg)
Directory tree walk with callback function.
[...] No semantics are defined for, or required of, arg, beyond
that arg is always passed to func. It can be used, e.g., to
pass a filename pattern, or a mutable object designed to
accumulate statistics. Passing None for arg is common.
| * what if i want to print the full path?
Use os.path.join():
def visit(arg, dirname, fnames):
for file in fnames:
if file.endswith('.html'):
print os.path.join(dirname, file)
| * what if i want to print a particular type of file, for example only
| directories.
Use os.path.isdir()
| * how to find out about a particular function or method, or what
| modules are available?
In python 2.2, type help() at a (python) prompt, and then 'modules' to
give a list of all modules available on your system. You can use
help() on a type or function to read its documentation (try
'help(file)' for example). The full current library reference is at:
http://www.python.org/doc/current/lib/lib.html
Jeremy.
More information about the Python-list
mailing list