Open script
Steve Holden
sholden at bellatlantic.net
Thu Feb 10 08:56:38 EST 2000
Pedro:
Although, technically, directories are files, the Python file reading
utility functions don't have any way of interpreting their contents.
Consequently you will get an IOError (in my case, 21, "Is a directory").
Try taking a look at the os library module documentation. You will see
it includes various useful bits and pieces. You might find os.listdir
especially useful, as it returns a list of the entries in a directory.
>>> import os
>>> os.listdir("r:/ZipDisks/Text Editors")
['emacs-19_34_6-bin-i386_tar.gz', 'pfe0702i.zip', 'UltraEdit32.zip',
'cooledit-3_12_0_tar.tar', 'vim-5_5-src_tar.tar']
>>>
Good luck.
Steve
> Pedro Silva wrote:
>
> Hi,
>
> I'm trying to use OPEN to open a folder, because I need to get the content of
> that folder.
> This folder is in the filesystem.
>
> The code line that I'm using is:
>
> f = open('var/spool/news/articles','r')
> fs = f.realines()
???? f.readlines() ?????
> return fs
>
> But this is giving me and error. Is this correct or because articles is a
> folder and is because of that that the error is displayed.
>
> Please send me your answers to: psilva at ruido-visual.pt
>
> Thanks,
>
> Pedro
--
"If computing ever stops being fun, I'll stop doing it"
More information about the Python-list
mailing list