msg195097 - (view) |
Author: Dan Loewenherz (dloewenherz) |
Date: 2013-08-13 20:54 |
Basically, when creating a NamedTemporaryFile, passing a value to the "suffix" parameter has no effect unless it's prepended with a period. IMO, there are three options here... 1. Add a note in the documentation that this parameter only accepts period-prepended values (not ideal but better than the status quo). 2. Change the behavior to throw an exception when a non-period prepended value is provided (probably bad since it would break stuff). 3. Strip invalid values from this input and silently fail if the resulting string is of length 0 (might also break stuff). |
|
|
msg195495 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-08-17 17:21 |
>>> import tempfile >>> f = tempfile.NamedTemporaryFile(suffix='$') >>> f.name '/tmp/tmpumyks8ju$' I see an effect. |
|
|
msg195496 - (view) |
Author: Ezio Melotti (ezio.melotti) *  |
Date: 2013-08-17 17:45 |
Works for me on Linux too (all branches, with different types of suffix). Maybe it's a Windows issue? |
|
|
msg195514 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2013-08-17 19:59 |
'Filename extensions' are a proper subset of 'suffixes'. https://en.wikipedia.org/wiki/Filename_extension Dan 'solutions' indicates that he thinks that the two sets are or should be the same, which they are not. The only thing that is DOS/Windows specific is its more special treatment of '.'. That said, I can see how a Windows user might be confused by the following awkward sentence. If 'suffix' is specified, the file name will end with that suffix, otherwise there will be no suffix. as 'no suffix' is easily read as 'no extension. The manual, but not the docstring, addresses the possible confusion by adding mkstemp() does not put a dot between the file name and the suffix; if you need one, put it at the beginning of suffix. I think the prefix sentence is also a bit awkward. If 'prefix' is specified, the file name will begin with that prefix, otherwise a default prefix is used. I think both parameters should be explained in both docstring and doc with one shorter and clearer entry. "The file name will begin with *prefix* (default 'tmp') and end with *suffix* (default ''). The is no automatic addition of a period ('.') before the suffix." |
|
|
msg195516 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-08-17 20:25 |
I don't think any explanation is needed. A docstring should be short, we can't duplicate a manual in it. The mentioning suffix default is redundant because it already exposed in the function signature. The mentioning prefix default adds duplication. The purpose of introducing of the template attribute is get rid of such duplication. |
|
|
msg195518 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2013-08-17 20:49 |
It would be fine with me to shorten the suggestion and not repeat the defaults. They are currently in both doc and docstring, but with *more* words than I used. "The file name will begin with *prefix* and end with *suffix*. There is no automatic addition of a period ('.') before the suffix." The explanation of . is already in the doc in a wordier form (too wordy in my view). The above is much shorter than what is currently in the docstring. |
|
|
msg202253 - (view) |
Author: Jason Myers (Jason.Myers) |
Date: 2013-11-06 03:18 |
This is a patch based on terry.reedy 's suggestion |
|
|
msg265098 - (view) |
Author: Martin Panter (martin.panter) *  |
Date: 2016-05-07 22:44 |
I think Terry may have had the mkstemp() doc string in mind. The NamedTemporaryFile() doc string already points to that function, and it doesn’t make sense to single NamedTemporaryFile() out above other functions. |
|
|
msg265105 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2016-05-07 23:37 |
Correct. The doc I quoted was for the unlying mkstemp function. I should have said so even though this fact was easily discovered. So by docstring, I meant the one for mkstemp also, which is currently 27 lines. The docstring for the high level functions should not change. I proposed to shorten the docstring by combining the sentences for prefix and suffix, while adding a bit of info. I decided to withdraw this suggestion and close this issue. |
|
|