Path: ...!feed.opticnetworks.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Mark Bourne Newsgroups: comp.lang.c Subject: Re: Baby X is bor nagain Date: Tue, 18 Jun 2024 21:09:25 +0100 Organization: A noiseless patient Spider Lines: 29 Message-ID: References: <20240613002933.000075c5@yahoo.com> <20240613174354.00005498@yahoo.com> <20240617002924.597@kylheku.com> <20240618115650.00006e3f@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 18 Jun 2024 22:09:27 +0200 (CEST) Injection-Info: dont-email.me; posting-host="f6dfeab3d9e88a3420799621ce1dfd5f"; logging-data="1606038"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18asr6gwcofTnDCuCkzpEl1" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 SeaMonkey/2.53.18.2 Cancel-Lock: sha1:QFyndDc/1TC7+c3J6vKlLslj2Jk= In-Reply-To: Bytes: 2525 Malcolm McLean wrote: > On 18/06/2024 13:36, David Brown wrote: >> #!/usr/bin/python3 >> import sys >> >> if len(sys.argv) < 2 : >>      print("Usage: sums.py ") >>      sys.exit(1) >> >> data = list(map(int, open(sys.argv[1], "r").read().split())) >> n = len(data) >> s = sum(data) >> print("Count: %i, sum %i, average %i" % (n, s, s // n)) >> >> >> > And here's a simple task for you. Our filesystem uses a new technology > and is a bit dicey. Occasionally you will get a read error. Can you > modify the python to print out that a read error has occurred? No modification required ;) A read error will raise an exception; unhandled exceptions are printed to stderr along with a stack trace, and the program terminates with a failure status. If you don't want the stack trace, you can handle the exception to just print a message and exit, but this is comp.lang.c, not comp.lang.python. -- Mark.