File naming [was Re: Bug reporting impossible]

Nick Maclaren nmm1 at cus.cam.ac.uk
Fri Jun 30 04:58:45 EDT 2006


In article <mailman.7636.1151650599.27775.python-list at python.org>,
"Fredrik Lundh" <fredrik at pythonware.com> writes:
|> 
|> > |> Why would you have a file named '<stdin>' in your current directory?
|> >
|> > Why would Python search for one? :-)
|> >
|> > In both cases, the normal answer is "Someone made a mistake" but, if
|> > you have a script that creates a files of the same names specified in
|> > the current directory, what name should it use if you specify stdin?
|> 
|> given that "<stdin>" is an invalid filename on some platforms, why would any
|> serious programmer use "<stdin>" for an external file ?

You can't be serious, surely?

Firstly, why does Python?  Well, I can answer that :-)

Secondly, EVERY string is an invalid filename on some platforms, without
exception!  As every single (not system-specific) language has done since
languages imported the concept of filenames, Python says that the set of
strings that are valid filenames is implementation-dependent or perhaps
implementation-defined.

Thirdly, I had better explain what a LOT of programs and scripts actually
do.  You have a command 'fred' that takes filenames as arguments and, if
there are none, uses stdin; as part of its function, it needs to create a
file of the same name as those in its arguments, in the current directory.
What filename should it use for stdin?

I sincerely HOPE that you are not proposing to use the null filename
(which could and probably still can be created on some systems), as it is
a gibbering nightmare to handle thereafter, and a poor sod of an ordinary
user has little hope of cleaning up the mess.  Been there - done that for
them :-)

It can't use 'stdin', as that is a possible file name, so it uses an
obvious derivation that is unlikely to be created by accident.  '<stdin>'
is one of the standard conventions - I am one of perhaps a few hundred
(perhaps more) people who invented it independently, 20 years back, but
doubt that I was even close to the first.  It is quite a good name for
Unix, as you can't easily create it by accident in any normal shell.

|> > It is one of the standard conventions, which is (after all) why Python
|> > is searching for it.
|> 
|> the only reason Python's searching for it is that the CLI implementation passes
|> "<stdin>" as the second argument to compile:
|> 
|>     http://pyref.infogami.com/compile

And the reason that it does that is because it is using one of the standard
conventions for naming stdin.  Python didn't INVENT that convention, you
know.

The bug isn't in passing an information string "<stdin>" but in using
that string (which is not meant to represent a real file) to perform a
file search.


Regards,
Nick Maclaren.



More information about the Python-list mailing list