Deutsch English Français Italiano |
<mailman.93.1731348414.4695.python-list@python.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!3.eu.feeder.erje.net!feeder.erje.net!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail From: dieter.maurer@online.de Newsgroups: comp.lang.python Subject: Re: FileNotFoundError thrown due to file name in file, rather than file itself Date: Mon, 11 Nov 2024 18:24:44 +0100 Lines: 33 Message-ID: <mailman.93.1731348414.4695.python-list@python.org> References: <87v7wt986z.fsf@zedat.fu-berlin.de> <26418.15836.335097.984240@ixdm.fritz.box> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de j4wU7TXqQIYcT5aO1igmuwsge5dGrS4RU0EJjSd/eKzQ== Cancel-Lock: sha1:3pQAh5qMcqyhRBtQ7O7/s/MzYs8= sha256:/uq2BZ6TRLJOjkEflfN96T25kBVQyncL8jJsUsLQ6sE= Return-Path: <dieter.maurer@online.de> X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org Authentication-Results: mail.python.org; dkim=pass reason="2048-bit key; unprotected key" header.d=online.de header.i=dieter.maurer@online.de header.b=DcDadR6c; dkim-adsp=pass; dkim-atps=neutral X-Spam-Status: OK 0.053 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; 'received:212.227': 0.07; 'subject:name': 0.07; '(python': 0.09; 'cc:addr:python-list': 0.09; 'subject:, \n ': 0.09; 'log': 0.12; 'cc:no real name:2**0': 0.14; 'bennett': 0.16; 'found.': 0.16; 'generating': 0.16; 'program:': 0.16; 'python': 0.16; 'cc:addr:python.org': 0.20; 'exception': 0.22; 'subject:file': 0.22; 'code': 0.23; 'received:de': 0.23; '(and': 0.25; 'cc:2**0': 0.25; 'skip:{ 20': 0.26; 'error': 0.29; 'received:kundenserver.de': 0.32; 'received:mout.kundenserver.de': 0.32; 'header:In-Reply-To:1': 0.34; 'following': 0.35; '...': 0.37; 'file': 0.38; 'quite': 0.39; 'wrote': 0.39; '(see': 0.40; 'file:': 0.40; 'learn': 0.40; 'should': 0.40; 'likely': 0.61; 'between': 0.63; 'your': 0.64; 'full': 0.64; 'thus': 0.64; 'look': 0.65; 'well': 0.65; 'terms': 0.69; 'raised': 0.70; 'received:80': 0.70; 'major': 0.78; 'clause': 0.84; 'surprised': 0.84; 'subject:than': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=online.de; s=s42582890; t=1731348411; x=1731953211; i=dieter.maurer@online.de; bh=MN8+j1xHIqyz/dbOcn5PuBRH1fXI+duOHVsAgPg0ugU=; h=X-UI-Sender-Class:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:Date:From:To:Cc:Subject: In-Reply-To:References:cc:content-transfer-encoding:content-type: date:from:message-id:mime-version:reply-to:subject:to; b=DcDadR6c5kOFDZ6j9hzuyY7cfwcCGdBzRByH2JjPgize41efhG83RKSuemmSEVJO cKx2tqUXfVPBfYqnAGTpj8YPh+qISWtfySa/s1yyAPZQce0/wCDFsLUteuR5TVoVy TticYEesVmv+BhKjyxbNtT17vPZJIojqRt7BE+5IlYSLG4W9vxEYM3p3Y5KMoKzOU NeYnTlNwBGqHcl0VkZ/ShiE9sfnkCkOV+vlGvLotI18TJEJxNFkuVPXGqYXi9BUtF nc8XU7dZwOtHmNK5BpQuRAQunLpFXayV55qulfaqx7JaHWDr7Oj1zrulZRMeIadzE OIIPcpFGQ5t1uZOpvQ== X-UI-Sender-Class: 6003b46c-3fee-4677-9b8b-2b628d989298 In-Reply-To: <87v7wt986z.fsf@zedat.fu-berlin.de> X-Mailer: VM 8.0.12-devo-585 under 21.4 (patch 24) "Standard C" XEmacs Lucid (x86_64-linux-gnu) X-Provags-ID: V03:K1:a584Z6ojDijytenwJlGQtRISlhg8GMsQqoxaxdxN7hdntvh0pAe MWIjK+TGwSSzN85LDLAk5TSNJoG9i8TiS7ZJK3PT1hxPjp0m4v7eK1FdQH0985d2NNJ1mhz uOSnYAfePCbf+aSRe8oKsgyywSU8K+PxjAf8bWF1zQ7X4/xJuKUHaoAaunr51fFwnIl5FqS YsrnAAq0OODOOMWclBISA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:lMo/raPtesg=;5NJdf8J+09mPr7nDExoo7I5nD/B yX9lW32g4oW1EJ3GNs9UM4kLVQIGdgZwQwRbIZVyk90QgR8D3arWw17v9GRnZTIkjSS64i4Gd m9d/xqmyiIecYT3oJZbX9OsrazjHQqSbtBm1oc4DB2cb1Bx/KZFiP1RtBUj8qv7HD/hweIxNs bQujK2rS/Tdi9E94IDfIsB0RjRp88ElGBdXY2g1ZuDSdwbf9tsWcNrN+XyMoDwLziQst9RA0q wG0KFMei5hU1RTdUBM9/OKQl6BFvxlVz8kFPRi98y8t0dd8NRUQkvjwqqdBcd+d4parZU+i0Y GnTfjMhtMSrj4rPCw9xLgLIMv7VMy7vf/CHZKB94NLZeAsxD3zM0k++g1wiv/O/8kAb7x9YL5 7xTLEzdG5GawPLe2ukpSPPcm9Lv9yVaz8ItkjSveV7clwTR1V/0XBdZsLxtCc8V8C7lHwmoeb 5RLC263OFH15JHM16isRr6TZ+eZMF9GlSx7TOJxwwELXxqWulC6TpC+lGnHK+CDAKQnLdBDoB Go8t8m5x7zSVZvUQuYTrE25//JM3rK4M8uvmx9dSHFuyYj/YykO7KDAA8zCVCmt8etQ9rFUqD tFoPWwbJOKRet+mFpotcvXOzW3LdARyk8TIHUzBdoiaW/87Dzy4EFf/LulEX2/1w176bLmwMp Fh7sTDSxDKPhkhYMN7/n6SDZKrmFjDi0OAOyErUNM70/P/PawjDX3Vgk2zI9Bngo6BA6TSKkt FkkonYXVpDrLC1qhgkQUhx6gDEKYpOxQQ== X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.39 Precedence: list List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> List-Archive: <https://mail.python.org/pipermail/python-list/> List-Post: <mailto:python-list@python.org> List-Help: <mailto:python-list-request@python.org?subject=help> List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> X-Mailman-Original-Message-ID: <26418.15836.335097.984240@ixdm.fritz.box> X-Mailman-Original-References: <87v7wt986z.fsf@zedat.fu-berlin.de> Bytes: 6231 Loris Bennett wrote at 2024-11-11 15:05 +0100: >I have the following in my program: > try: > logging.config.fileConfig(args.config_file) > config = configparser.ConfigParser() > config.read(args.config_file) > if args.verbose: > print(f"Configuration file: {args.config_file}") > except FileNotFoundError: > print(f"Error: configuration file {args.config_file} not found. Exiting.") Do not replace full error information (including a traceback) with your own reduced error message. If you omit your "try ... except FileNotFoundError` (or start the `except` clause with a `raise`), you will learn where in the code the exception has been raised and likely as well what was not found (Python is quite good with such error details). > ... >My questions are: > >1. Should I be surprised by this behaviour? Your code contains a major weakness (see above); thus surprises are not unlikely. >2. In terms of generating a helpful error message, how should one > distinguish between the config file not existing and the log file not > existing? You look at the error information provided by Python (and its library) rather than hiding it.