Re: What to do to correct the error written below:

2022-04-12 Thread Greg Ewing

On 12/04/22 2:28 am, Peter Pearson wrote:

By looping over elements in "books" and incrementing counter i,
which is used as an index both for "books" and for "students",
you will produce an error whenever the number of books exceeds
the number of students.


More fundamentally, it assumes there is a one-to-one correspondence
between the list of books and the list of students.

It doesn't look like that is true here -- one is a list if students with
a given student ID (which doesn't make sense -- surely there should only
be one?) and the other is a list of books with a given isbn (presumably
all copies of the same book).

It would make more sense for there only to be a list of books, and just
one reference to the student, at that point in the code.

Generally this whole piece of code seems hopelessly confused and needs
to be re-thought.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: What to do to correct the error written below:

2022-04-12 Thread Peter Pearson
On Tue, 12 Apr 2022 04:56:22 -0700 (PDT), NArshad wrote:
>
>>By looping over elements in "books" and incrementing counter i,
>>which is used as an index both for "books" and for "students",
>>you will produce an error whenever the number of books exceeds
>>the number of students.  Is there some reason to assume that the
>>number of books cannot exceed the number of students?
>
> Since this is an online library the number of students can be any when
> compared to number of books or the number of students has nothing to
> do with the number of books.

1. The code assumes that the number of books does not exceed the
   number of students.

2. You report that the number of students has nothing to do with
   the number of books.

3. Therefore we have identified an erroneous assumption in the code.

Mystery solved.

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Circular Import

2022-04-12 Thread Stefano Ovus
How can I avoid circular imports keeping separated modules ?

-- square.py

from circle import Cirle
class Square:
  def __init__(self):
...
  @classmethod
  def from_circle(cls, circle: Circle) -> Square:
...
return cls(...)


-- circle.py

from square import Square
class Circle:
  def __init__(self):
...
  @classmethod
  def from_square(cls, square: Square) -> Circle:
...
return cls(...)

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Circular Import

2022-04-12 Thread Stefano Ovus
found a solution: importing modules instead of classes, ex.

-- square.py

import circle

...
@classmethod
  def from_circle(cls, circle: circle.Circle) -> Square:
...
return cls(...)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Circular Import

2022-04-12 Thread Chris Angelico
On Wed, 13 Apr 2022 at 03:37, Stefano Ovus  wrote:
>
> found a solution: importing modules instead of classes, ex.
>
> -- square.py
>
> import circle
>
> ...
> @classmethod
>   def from_circle(cls, circle: circle.Circle) -> Square:
> ...
> return cls(...)

Yep! Good solution.

Be aware that this will only work if both modules have fully executed
before the references are actually needed. Usually not a problem, but
if you have code that runs at top-level that needs to refer to the
other module (as opposed to simply defining classes and methods, where
those methods are going to refer to the other module when they get
called), it might not work. But that's no different from any other
circular dependency.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion for Linux Distro (from PSA: Linux vulnerability)

2022-04-12 Thread Marco Sulla
On Tue, 29 Mar 2022 at 00:10, Peter J. Holzer  wrote:
> They are are about a year apart, so they will usually contain different
> versions of most packages right from the start. So the Ubuntu and Debian
> security teams probably can't benefit much from each other.

Well, this is what my updater on Lubuntu says to me today:

Changes for tcpdump versions:
Installed version: 4.9.3-0ubuntu0.18.04.1
Available version: 4.9.3-0ubuntu0.18.04.2

Version 4.9.3-0ubuntu0.18.04.2:

  * SECURITY UPDATE: buffer overflow in read_infile
- debian/patches/CVE-2018-16301.patch: Add check of
  file size before allocating and reading content in
  tcpdump.c and netdissect-stdinc.h.
- CVE-2018-16301
  * SECURITY UPDATE: resource exhaustion with big packets
- debian/patches/CVE-2020-8037.patch: Add a limit to the
  amount of space that can be allocated when reading the
  packet.
- CVE-2020-8037

I use an LTS version. So it seems that Ubuntu benefits from Debian
security patches. Not sure about the contrary.
-- 
https://mail.python.org/mailman/listinfo/python-list