Documentation for checking if '-' has been passed to File param #1511
Comments
|
I don't think this is in scope for Click. You would check in whatever way you would check in Python in general, by examining some theoretical property of the file object. In most cases, the name of the file will be the special value |
|
Just chiming in to add that another property of a file that you can inspect to check whether it probably corresponds to the process’s original stdin is its .fileno() value. By convention, the three file descriptors 0, 1, and 2 represent standard input, standard output, and standard error, respectively. I think this should work even if something like pdb, pytest, etc. reassigns the corresponding sys attributes. However, it will not work if something dup’s and then closes the original stdin, but maybe that’s a feature and not a bug depending on what you’re trying to do. |
Hi there,
This is not a bug report, but rather a documentation question. Parameters of type
Fileinterpret-as stdin or stdout depending on the mode. My question is: how to check if-has been passed to my parameter?With the current version installed in my environment, I checked that the following works:
However, as there are other ways of opening stdin (instead of using
sys.stdindirectly) and the documentation does not guarantee that the value of the parameter will besys.stdinfor the"-"input, I'm not sure if this code is safe regarding future releases of Click.Environment
The text was updated successfully, but these errors were encountered: