Hi, Moshe Zadka: > I've found a need for the following function: > > def copyfile(fin, fout): > while 1: > buf = fin.read(4096) > if not buf: > break > fout.write(buf) > > In several different places (modules I've written, SimpleHTTPServer uses > it, urllib has that code inlined somewhere, etc.) > > (Of course, 4096 should be a parameter, but that's nits) > > Can anyone suggest a module in which this function would belong? A very similar function lives at a somewhat hidden flat in the third floor of the standard library building. ;-) It is called 'shutil.copyfile'. See '......html/lib/module-shutil.html' for more information. 'shutil.copyfile' however takes filenames as arguments and contains the loop sketched above as inline code. I see two possibilities: 1. It would be easy to skip the open and close operations in 'shutil.copyfile', if either 'src' or 'dst' are already open file objects instead of strings. 2. Or you factor out the copy loop operation above and rename it into 'copycontent' or 'copybytes' or whatever. Regards, Peter
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4