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


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-11 Thread Dennis Lee Bieber
On Mon, 11 Apr 2022 00:14:49 -0700 (PDT), NArshad 
declaimed the following:


>for i in issuedBooks:

Loop control variable is "i"...

>i=0

Control variable "i" has been overwritten so any use of "i" following
this is suspicious

>for l in books:

Inner-loop control variable is "l" -- and does not seem to be used for
anything following...

>
> t=(students[i].user,students[i].user_id,books[i].name,books[i].isbn,issuedBooks[0].issued_date,issuedBooks[0].expiry_date,fine)
>i=i+1


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2022-04-11 Thread Dennis Lee Bieber
On 11 Apr 2022 14:28:51 GMT, Peter Pearson 
declaimed the following:

>Is this homework?  In this newsgroup, by custom, homework problems
>should be announced as such, since the best answer to a homework
>question is different from the best answer to a real-life problem.
>
It's a return to a long cryptic thread from January...
<199c23c7-de58-44ae-a216-760c8f36c5...@googlegroups.com>
"What to write or search on github to get the code for what is written
below:"

It is nice to see that the insistence on using Excel for the data
storage seems to have been dropped (at least, the code shown appears to be
something like SQLAlchemy), but the OP really should spend a few weeks
studying database normalization and use of foreign keys -- concepts which,
properly applied, means there is no need for these confusing hand-tracked
indices.


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2022-04-11 Thread Peter Pearson
On Mon, 11 Apr 2022 00:14:49 -0700 (PDT), NArshad wrote:
[snip]
> books = list(models.Book.objects.filter(isbn=i.isbn))
> students = list(models.Student.objects.filter(user=i.student_id))
> i=0
> for l in books:
> 
> t=(students[i].user,students[i].user_id,books[i].name,books[i].isbn,issuedBooks[0].issued_date,issuedBooks[0].expiry_date,fine)
> i=i+1
> details.append(t)
[snip]

Is this homework?  In this newsgroup, by custom, homework problems
should be announced as such, since the best answer to a homework
question is different from the best answer to a real-life problem.

Back to the problem:

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?



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


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

2022-04-10 Thread Peter Pearson
On Sat, 9 Apr 2022 04:59:05 -0700 (PDT), NArshad  wrote:
> I have accidentally deleted one account in a Django project because of
> which one of the pages is no more accessible and is giving the error
> written below:
>
> IndexError at /view_issued_book/
> list index out of range
>
> and the error is in the line: 
>
> t=(students[i].user,students[i].user_id,books[i].name,books[i].isbn,issuedBooks[0].issued_date,issuedBooks[0].expiry_date,fine)
>  
[snip]

Without seeing more of the code, one can only guess, but it appears
that the data being processed reside in arrays named "students" and "books",
which are indexed by an integer i.  The "list index out of range" error
probably results from i being too large -- running off the end of the
array, perhaps because of the deleted account.  You could confirm this
by printing i, len(students), and len(books) just before the failing
line.

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