Re: can you improve this text-only beginner copy program? (Posting On Python-List Prohibited)

Lawrence D’Oliveiro <[email protected]> Thu, 28 Aug 2025 01:36:41 -0000 (UTC)
Newsgroups comp.lang.python
Organization A noiseless patient Spider
Message-ID <[email protected]>
On Wed, 27 Aug 2025 11:03:22 -0300, Ethan Carter wrote:

> def copy(s, d):
>   """Copies text file named S to text file named D."""
>   with open(s) as src:
>     with open(d, "w") as dst:
>       try:
>         dst.write(src.read())
>       except Exception:
>         os.remove(d)
>         raise

copy("/proc/sys/kernel/random/uuid", "/dev/full")

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
OSError: [Errno 28] No space left on device

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
Cell In[5], line 11
      8         os.remove(d)
      9         raise
---> 11 copy("/proc/sys/kernel/random/uuid", "/dev/full")

Cell In[5], line 4, in copy(s, d)
      2 """Copies text file named S to text file named D."""
      3 with open(s) as src:
----> 4   with open(d, "w") as dst:
      5     try:
      6       dst.write(src.read())

OSError: [Errno 28] No space left on device