Best way to check if there is internet?

Chris Angelico rosuav at gmail.com
Tue Feb 22 11:01:25 EST 2022


On Wed, 23 Feb 2022 at 02:33, Chris Green <cl at isbd.net> wrote:
>
> Chris Angelico <rosuav at gmail.com> wrote:
> > On Tue, 22 Feb 2022 at 19:33, Abdur-Rahmaan Janhangeer
> > <arj.python at gmail.com> wrote:
> > >
> > > As discussed here but, it would have been nevertheless great to have this
> > > tiny function instead of
> > > nothing
> > >
> >
> > Here's a function that determines whether or not you have an internet
> > connection. It's almost as reliable as some of the other examples
> > given - I know this, because I tried it ten times, and it gave the
> > correct result every time!
> >
> > def has_internet():
> >     return True
> >
> > Tell me, is it useful to have something that doesn't always give the
> > right answer, even if it usually does? Is there any value whatsoever
> > in a lie?
> >
> That's sort of in the same area as a stopped clock being right more
> often than one that runs just a bit slow (or fast).  :-)
>

Oddly enough, if your options for clocks are "right twice a day",
"right once a week", "right once a month", and "never right", the most
useful is probably actually the one that's never right, because if it
ticks at the right rate but is set slightly wrong, it'll always be
exactly that same offset away from correct (which you can adjust for).

But a function to tell you whether you have the internet or not is
like a clock that tells you whether you have time or not. In a
technical (and vacuous) sense, yes, you do... in a practical and
useful sense, who knows?

ChrisA


More information about the Python-list mailing list