[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Tarek Ziadé
Tarek Ziadé added the comment: @Antoine, @Eric: After some more thoughts a contextlib makes more sense. I also have a use case for an atomic copytree() but I guess that can be an option in copytree() -- ___ Python tracker

[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Antoine Pitrou
Antoine Pitrou added the comment: > Giving the ability to the developers to work in a context manager > means that you potentially give them the ability to break this > atomicity. AFAICT this doesn't make sense. The writing isn't atomic, the renaming is. -- ___

[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Eric Smith
Eric Smith added the comment: I agree that with the addition of the new requirement that it be an atomic write, it should be in a library. I'd also do it as a context manager, since that's the more general case. distutils2 can either call the context manager version, or have a trivial functi

[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Jean-Paul Calderone
Jean-Paul Calderone added the comment: Considering that it's extremely difficult to implement this correctly and in a cross-platform way, I think it makes sense as a stdlib addition (though I'd add it as a method of a `path` type rather than to the "shell utilities" module ;). -- nosy

[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Tarek Ziadé
Tarek Ziadé added the comment: This idiom makes sense when you want to do some things with an open file, and replaces the usual try..finally idiom. That's not what we want to do here. We want to write data in a file in a single step, in an atomic manner. Giving the ability to the developers

[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Antoine Pitrou
Antoine Pitrou added the comment: > Well, a context manager sounds overkill since we just want to write > some content in a file (and nothing else during that context). Using a context manager, though, is the recommended idiom to write files. I think there's a value in remaining consistent. We

[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Tarek Ziadé
Tarek Ziadé added the comment: Notice that "contents" could be replaced here by an iterator, that would return data to send to write() -- ___ Python tracker ___

[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Tarek Ziadé
Tarek Ziadé added the comment: Well, a context manager sounds overkill since we just want to write some content in a file (and nothing else during that context). I think a simple call is straightforward: shutil.atomic_write("foo", "contents", mode="wb") -- ___

[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Dan Buch
Changes by Dan Buch : -- nosy: +meatballhat ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.o

[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Antoine Pitrou
Antoine Pitrou added the comment: > @Antoine: Yes, that would be the idea (provide a robust pattern by > using a temporary file, then rename it) Then perhaps it would be better as a context manager: with shutil.atomic_write("foo", "wb") as f: f.write("mycontents") --

[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Tarek Ziadé
Tarek Ziadé added the comment: @Eric: remember that distutils is frozen, so it won't be removed. And historically Distutils code was meant to be 2.4 compatible (thus, no with) @Antoine: Yes, that would be the idea (provide a robust pattern by using a temporary file, then rename it) -

[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Eric Smith
Eric Smith added the comment: Does the standard library really need something so trivial? I'd put it in your own program. And I'd make the one in distutils private (and fix it to use a with statement). -- nosy: +eric.smith ___ Python tracker

[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Antoine Pitrou
Antoine Pitrou added the comment: This sounds silly to me. You can write a file in two lines: with open("foo", "wb") as f: f.write(contents) If you want to do something more useful, you can add a function for atomic writing of a file. -- nosy: +pitrou versions: +Python 3.2 -Pytho

[issue8604] Alias for distutils.file_util.write_file in e.g. shutils

2010-05-03 Thread Olemis Lang
New submission from Olemis Lang : Often I have the contents to be written in a file at a given path that I know as well. I recently tried to find a function in stdlib to do that and to my surprise this is what I found : - Such function exists - It's `distutils.file_util.write_file` IMO the la