Re: can you improve this text-only beginner copy program?

2025-08-28 Thread Roel Schroeven
Op 28/08/2025 om 18:02 schreef MRAB: On 2025-08-28 03:08, Grant Edwards via Python-list wrote: In the event of an exception, you attempt to remove the destination file BEFORE exiting the `with` statement. While that might succeed on some platforms, it will potentially fail on others. Specifica

Re: can you improve this text-only beginner copy program?

2025-08-28 Thread Grant Edwards via Python-list
On 2025-08-28, Roel Schroeven wrote: >> If an OS did let you delete an open file, how would you expect it to >> behave? Would you still be able to use the file? Would the file be >> marked for deletion and be deleted when it was finally closed? > Unix-like operating systems do let you delete a

Re: can you improve this text-only beginner copy program?

2025-08-28 Thread Grant Edwards via Python-list
On 2025-08-28, Mark Bourne wrote: > Ethan Carter wrote: >> PS. Is it just me or there's just us in this used-to-be-very-active >> group? Thanks for being my teacher here. Have a good day! >> > > Until a few months ago, there was a gateway that forwarded messages both > ways between this newsg

Re: can you improve this text-only beginner copy program?

2025-08-28 Thread Mark Bourne
Ethan Carter wrote: PS. Is it just me or there's just us in this used-to-be-very-active group? Thanks for being my teacher here. Have a good day! Until a few months ago, there was a gateway that forwarded messages both ways between this newsgroup and a mailing list. It seems to have stop

Re: can you improve this text-only beginner copy program?

2025-08-28 Thread Mark Bourne
Stefan Ram wrote: Ethan Carter wrote or quoted: 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 In Python there ar

Re: can you improve this text-only beginner copy program?

2025-08-28 Thread MRAB
On 2025-08-28 03:08, Grant Edwards via Python-list wrote: On 2025-08-27, Chris Angelico via Python-list wrote: On Thu, 28 Aug 2025 at 01:28, 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: tr

Re: can you improve this text-only beginner copy program?

2025-08-28 Thread dn via Python-list
The suggestion (below) is good-practice. However, it's advanced-Python compared to the OP's first-course progress. What is disappointing, is that instead of general strings as file-names the class has not been introduced to pathlib (https://docs.python.org/3/library/pathlib.html). PS Ethan:

Re: can you improve this text-only beginner copy program?

2025-08-28 Thread dn via Python-list
On 29/08/25 10:52, Grant Edwards via Python-list wrote: On 2025-08-28, Mark Bourne wrote: Ethan Carter wrote: PS. Is it just me or there's just us in this used-to-be-very-active group? Thanks for being my teacher here. Have a good day! Until a few months ago, there was a gateway that for