On 2021-01-25 at 00:29:41 +1100, Steven D'Aprano <st...@pearwood.info> wrote:
> On Sat, Jan 23, 2021 at 03:24:12PM +0000, Barry Scott wrote: > > > I think that you are going to create a bug magnet if you attempt to auto > > detect the encoding. > > > > First problem I see is that the file may be a pipe and then you will block > > until you have enough data to do the auto detect. > > Can you use `open('filename')` to read a pipe? Yes. Named pipes are files, at least on POSIX. And no. Unnamed pipes are identified by OS-level file descriptors, so you can't open them with open('filename'), but you can open them with os.fdopen. Once opened, such data sources "should be" interchangeable. > Is blocking a problem in practice? If you try to open a network file, > that could block too, if there are network issues. And since you're > likely to follow the open with a read, the read is likely to block. So > over all I don't think that blocking is an issue. If open blocks too many bytes, then my application never gets to respond unless enough data comes through the pipe. Consider protocols like FTP and SMTP, where commands and responses are often only handfuls of bytes long. OTOH, if I'm opening a file (or a pipe) for such a protocol, then both ends should know the encoding ahead of time and there's no need to guess. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/55ZMKKQES3EYMXZFYPHOT3WYOKXMUG3Q/ Code of Conduct: http://python.org/psf/codeofconduct/