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


Groups > comp.lang.python > #196991 > unrolled thread

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

Started by"Loris Bennett" <loris.bennett@fu-berlin.de>
First post2024-11-11 15:05 +0100
Last post2024-11-12 10:03 +0100
Articles 5 on this page of 25 — 14 participants

Back to article view | Back to comp.lang.python


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#196999

FromChris Angelico <rosuav@gmail.com>
Date2024-11-12 12:17 +1100
Message-ID<mailman.96.1731374262.4695.python-list@python.org>
In reply to#196991
On Tue, 12 Nov 2024 at 01:59, Loris Bennett via Python-list
<python-list@python.org> wrote:
> 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?

By looking at the exception's attributes rather than assuming and
hard-coding the path in your message? Or, even better, just let the
exception bubble.

ChrisA

[toc] | [prev] | [next] | [standalone]


#197002

From"Loris Bennett" <loris.bennett@fu-berlin.de>
Date2024-11-12 10:00 +0100
Message-ID<87h68cyggb.fsf@zedat.fu-berlin.de>
In reply to#196999
Chris Angelico <rosuav@gmail.com> writes:

> On Tue, 12 Nov 2024 at 01:59, Loris Bennett via Python-list
> <python-list@python.org> wrote:
>> 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?
>
> By looking at the exception's attributes rather than assuming and
> hard-coding the path in your message? Or, even better, just let the
> exception bubble.

As Dieter also pointed out, I obviously made a mistake in assuming that
I knew what 'FileNotFound' was referring to.

However, it strikes me as not immediately obvious that the logging file
must exist at this point.  I can imagine a situation in which I want to
configure a default log file and create it if it missing.

Cheers,

Loris

-- 
This signature is currently under constuction.

[toc] | [prev] | [next] | [standalone]


#197015

Fromdieter.maurer@online.de
Date2024-11-13 19:36 +0100
Message-ID<mailman.105.1731522974.4695.python-list@python.org>
In reply to#197002
Loris Bennett wrote at 2024-11-12 10:00 +0100:
> ...
>However, it strikes me as not immediately obvious that the logging file
>must exist at this point.  I can imagine a situation in which I want to
>configure a default log file and create it if it missing.

This is what happens usually:
if you open a file with mode `a` or `w`, the file is created
if it does not yet exist.

Thus, a missing log file should not give you the `FileNotFound`
exception.
Look at the exception details: they should tell you what really
was not found (maybe the directory for the logfile).

[toc] | [prev] | [next] | [standalone]


#197016

FromKushal Kumaran <kushal@locationd.net>
Date2024-11-13 14:40 -0800
Message-ID<mailman.106.1731538158.4695.python-list@python.org>
In reply to#197002
On Wed, Nov 13 2024 at 07:36:04 PM, dieter.maurer@online.de wrote:
> Loris Bennett wrote at 2024-11-12 10:00 +0100:
>> ...
>>However, it strikes me as not immediately obvious that the logging file
>>must exist at this point.  I can imagine a situation in which I want to
>>configure a default log file and create it if it missing.
>
> This is what happens usually:
> if you open a file with mode `a` or `w`, the file is created
> if it does not yet exist.
>
> Thus, a missing log file should not give you the `FileNotFound`
> exception.
> Look at the exception details: they should tell you what really
> was not found (maybe the directory for the logfile).

It is possible a directory along the path does not exist.

-- 
regards,
kushal

[toc] | [prev] | [next] | [standalone]


#197003

From"Loris Bennett" <loris.bennett@fu-berlin.de>
Date2024-11-12 10:03 +0100
Message-ID<87a5e4ygc1.fsf@zedat.fu-berlin.de>
In reply to#196999
Chris Angelico <rosuav@gmail.com> writes:

> On Tue, 12 Nov 2024 at 01:59, Loris Bennett via Python-list
> <python-list@python.org> wrote:
>> 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?
>
> By looking at the exception's attributes rather than assuming and
> hard-coding the path in your message? Or, even better, just let the
> exception bubble.

I didn't consider letting the exception bubble as is the top of the
code for a CLI program.  I was hoping to just catch what I thought might
be a common error of the config file being missing.

-- 
This signature is currently under constuction.

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web