Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #196995

Re: FileNotFoundError thrown due to file name in file, rather than file itself

Path csiph.com!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> (permalink)
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>
Xref csiph.com comp.lang.python:196995

Show key headers only | View raw


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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

FileNotFoundError thrown due to file name in file, rather than file itself "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-11-11 15:05 +0100
  Re: FileNotFoundError thrown due to file name in file, rather than file itself Left Right <olegsivokon@gmail.com> - 2024-11-11 17:04 +0100
    Re: FileNotFoundError thrown due to file name in file, rather than file itself "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-11-12 10:15 +0100
      Re: FileNotFoundError thrown due to file name in file, rather than file itself Left Right <olegsivokon@gmail.com> - 2024-11-12 20:10 +0100
        Re: FileNotFoundError thrown due to file name in file, rather than file itself Greg Ewing <greg.ewing@canterbury.ac.nz> - 2024-11-13 14:04 +1300
          Re: FileNotFoundError thrown due to (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-13 02:13 +0000
      Re: FileNotFoundError thrown due to file name in file, rather than file itself Mats Wichmann <mats@wichmann.us> - 2024-11-12 13:28 -0700
      Re: FileNotFoundError thrown due to file name in file, rather than file itself Chris Angelico <rosuav@gmail.com> - 2024-11-13 07:34 +1100
      Re: FileNotFoundError thrown due to file name in file, rather than file itself "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-11-13 08:11 +0100
        Re: FileNotFoundError thrown due to file name in file, rather than file itself Barry <barry@barrys-emacs.org> - 2024-11-14 16:01 +0000
      Re: FileNotFoundError thrown due to file name in file, rather than file itself Roel Schroeven <roel@roelschroeven.net> - 2024-11-13 10:12 +0100
      Re: FileNotFoundError thrown due to file name in file, rather than file itself Michael Torrie <torriem@gmail.com> - 2024-11-13 21:07 -0700
      Re: FileNotFoundError thrown due to file name in file, rather than file itself Left Right <olegsivokon@gmail.com> - 2024-11-14 08:03 +0100
      Re: FileNotFoundError thrown due to file name in file, rather than file itself Chris Angelico <rosuav@gmail.com> - 2024-11-14 19:13 +1100
      Re: FileNotFoundError thrown due to file name in file, rather than file itself D'Arcy Cain <darcy@VybeNetworks.com> - 2024-11-13 06:37 -0700
      Re: FileNotFoundError thrown due to file name in file, rather than file itself Ethan Furman <ethan@stoneleaf.us> - 2024-11-14 09:32 -0800
      Re: FileNotFoundError thrown due to file name in file, rather than file itself Michael Torrie <torriem@gmail.com> - 2024-11-14 08:44 -0700
        Re: FileNotFoundError thrown due to file name in file, rather than file itself Jon Ribbens <jon+usenet@unequivocal.eu> - 2024-11-14 18:12 +0000
  Re: FileNotFoundError thrown due to file name in file, rather than file itself dieter.maurer@online.de - 2024-11-11 18:24 +0100
  Re: FileNotFoundError thrown due to (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-11 21:05 +0000
  Re: FileNotFoundError thrown due to file name in file, rather than file itself Chris Angelico <rosuav@gmail.com> - 2024-11-12 12:17 +1100
    Re: FileNotFoundError thrown due to file name in file, rather than file itself "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-11-12 10:00 +0100
      Re: FileNotFoundError thrown due to file name in file, rather than file itself dieter.maurer@online.de - 2024-11-13 19:36 +0100
      Re: FileNotFoundError thrown due to file name in file, rather than file itself Kushal Kumaran <kushal@locationd.net> - 2024-11-13 14:40 -0800
    Re: FileNotFoundError thrown due to file name in file, rather than file itself "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-11-12 10:03 +0100

csiph-web