Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My First App
#5
(Feb-15-2023, 07:21 PM)buran Wrote:
(Feb-15-2023, 05:46 PM)BCopeland64 Wrote: Also, can you suggest a better way to iterate over the copy of the list rather than changing it as you mentioned?

Compare

spam = [1, 2, 2, 3]

for item in spam:
    if item == 2:
        spam.remove(item)

print(spam)
Output:
[1, 2, 3]
and
spam = [1, 2, 2, 3]

for item in spam[::]:
    if item == 2:
        spam.remove(item)

print(spam)
Output:
[1, 3]
It may be irrelevant in your case, but it's not clear if you want to allow duplicate names. In mark_complete you break immediatelly when name is found (it implies no duplicate names by design) but in mark_incomplete you iterate over whole list and this imply duplicate names.

Also, note that I use list.remove, not del list[i]
But my preference will be
spam = [1, 2, 2, 3]
spam = [item for item in spam if item != 2]
print(spam)
Check https://stackoverflow.com/q/1207406/4046632
With regards to DB part - there are plenty of trivial errors in the db.py that do not allow the code to run, I mean not run at all

Thanks again for the assistance. I think I fixed my habit and main.py files. I don't know where to begin on the db.py file since those errors escape me. Are we talking about indentation, the SQL, variables? I wrote a tester.db file that works just fine using the same logic, but in my original db.py file when I put the same logic behind classes and functions, it all goes out the window.
Reply


Messages In This Thread
My First App - by BCopeland64 - Feb-13-2023, 09:18 AM
RE: My First App - by buran - Feb-15-2023, 11:57 AM
RE: My First App - by BCopeland64 - Feb-15-2023, 05:46 PM
RE: My First App - by buran - Feb-15-2023, 07:21 PM
RE: My First App - by BCopeland64 - Feb-16-2023, 09:20 AM
RE: My First App - by buran - Feb-16-2023, 11:20 AM
RE: My First App - by BCopeland64 - Feb-16-2023, 11:52 AM
RE: My First App - by BCopeland64 - Feb-16-2023, 08:20 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020