questions

Xiaoxia Dong xdong at aer.com
Mon Oct 2 17:55:33 EDT 2000


Hans Nowak wrote:

> On 2 Oct 00, at 14:09, Xiaoxia Dong wrote:
>
> > i am working on one of the project which needs using python, i am trying
> > to read a directory and list all
> > the files there according to the directory tree. I am thinking to make
> > the directory name bold and trying to
> > have some format like a2ps in unix.  I am just writing the output to a
> > text file. I don't use any graphical interface. Can anybody help me with
> > this?
>
> I'm not sure what you mean here... if you want all files in a certain
> directory, you can use glob:
>
> >>> import glob
> >>> glob.glob("c:/PythonWin/*.*")
> ['c:/PythonWin\\UNWISE.EXE', 'c:/PythonWin\\python.exe',
> ... etc ... 'c:/PythonWin\\test1.py', 'c:/PythonWin\\logfile.txt',
> 'c:/PythonWin\\xref-results.html']
>
> If you want a files in all subdirectories in a tree, you should use
> os.path.walk:
>
> >>> import os
> >>> def visit(arg, dirname, names):
>         # just an example
>         print dirname, ":"
>         print names
>
> >>> os.path.walk("c:/foo/bar/", visit, 0)
> # should print list of subdirectories and their files
>
> Hope this will get you started,
>
> --Hans Nowak (zephyrfalcon at hvision.nl)
> You call me a masterless man. You are wrong. I am my own master.
> May a red dragon make a horoscope about your arms!

thank you very much for your help. I guess i did not make myself clear, I am
tyring to change the font of some
of the string i am going to write to a file and in overall i want my file
look pretty and elegant. Is there anyway i
can do it in python?

thanks,
xiaoxia





More information about the Python-list mailing list