David Layton <dmlay...@gmail.com> added the comment: Eric,
checked that the file exists But then you’d run into race conditions. The only sure was to say if a file can be opened is to open it. I think you misunderstand me. I am NOT suggesting that you open and close the file. I am saying that you should not open it in the first place. If I cannot open the file at the point in my program where I actually want to open it, then fine, I can decide, in my own code, what to do. propensity to encourage bad > coding. I think the problem is not as bad as you paint it. A great number of unclosed file handles may cause problem to some OSes, but that’s it. On the plus side, the fact that argparse accepts for its type argument any callable that can check and convert a string input is simple, clean and works. FileType is needed. Causing a problem on some OSes and not others is worse than causing a problem on all OSes as it increases the likelihood of buggy code passing tests and moving to production. I think argparse is wonderful; I just think that by having FileType not open the file, the number of it's use cases is increased. As it stands now, I would prefer the just pass the argument as a string argument and handling the opening myself unless: 1. I wanted my program to open the file at the very beginning of the program (where one traditionally handles arg parsing) 2. I wanted to exit on the first, and only, attempt to open the file 3. I really did not care if the file closed properly--which, granted, is often the case with tiny scripts The moment any of these is not true due to a change in requirements, I will have to refactor my code to use a filename arg. Where as if I start out with a bog-standard filename and open it myself, I can easily add the behaviour I want. I just don't see FileType as a big convenience. However, I do see that changing this would break backwards compatibility and would not want to see that happen. Perhaps a new FileNameType that does some basic, perhaps, optional checks would have wider use-cases. I hope this helps. David Layton On Fri, Feb 3, 2012 at 2:37 PM, Éric Araujo <rep...@bugs.python.org> wrote: > > Éric Araujo <mer...@netwok.org> added the comment: > > s/sure was/sure way/ > > ---------- > > _______________________________________ > Python tracker <rep...@bugs.python.org> > <http://bugs.python.org/issue13824> > _______________________________________ > ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue13824> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com