Newbie question: files..
Fredrik Lundh
fredrik at pythonware.com
Sun Oct 10 13:17:34 EDT 1999
Sonny Parlin <sparlin at openpro.org> wrote:
> WOW, now that's interesting! I never would have guessed something like
> that. Are you saying that perl code such as:
>
> while(<FD>) {
> print "$_\n";
> }
>
> could be faster than low level C code such as:
>
> while ((c = read (fd, buf, BUF_SIZE)) > 0)
> write (1, buf, c);
well, read and write are not really part
of the C library, you know...
> > unfortunately, Python's file object is still
> > layered on top of C's stdio. but that may
> > of course change some day...
>
> As opposed to unistd or fcntl?
as opposed to the stdio portions of the
standard C library (anything using the
FILE type, that is). unistd and friends
are POSIX, not C, and thus not available
on all platforms:
sample.c(1) : fatal error C1083: Cannot
open include file: 'unistd.h': No such file
or directory
oops!
on the other hand, read (or very similar
functions) are available on most platforms,
so it's definitely a good idea to use them
where possible. but on the other hand,
lots of code relies on the fact that you
can get a FILE* out of a Python file object,
so it's not as easy as it may seem.
but that doesn't stop people from working
on it. here's one attempt:
http://members.xoom.com/_XOOM/meowing/python/index.html
(there are other similar projects out there.
in some environments, read/write isn't the
fastest way to access a file...)
afaik, Perl peeks *inside* the stdio structures,
which means that while they're actually using
stdio, their optimisations doesn't work on all
stdio implementations...
</F>
More information about the Python-list
mailing list