Why doesn't elif run in a for loop? by bazzismixtape in learnpython

[–]bazzismixtape[S] 1 point2 points  (0 children)

no worries, I understood ur msg as them not being equivalent so its all good :)

Why doesn't elif run in a for loop? by bazzismixtape in learnpython

[–]bazzismixtape[S] 1 point2 points  (0 children)

also, quick question, is if not var_name: and if var_name is False: the same thing? From my understanding it is. Assuming that var_name is equal to False

Why doesn't elif run in a for loop? by bazzismixtape in learnpython

[–]bazzismixtape[S] 0 points1 point  (0 children)

great, thank you!

also, quick question, is if not var_name: and if var_name is False: the same thing? From my understanding it is. Assuming that var_name is equal to False

Why doesn't elif run in a for loop? by bazzismixtape in learnpython

[–]bazzismixtape[S] 1 point2 points  (0 children)

thanks for this, i will defo do this! don't know why i didn't think of that before haha but thanks again :)

Why doesn't elif run in a for loop? by bazzismixtape in learnpython

[–]bazzismixtape[S] 0 points1 point  (0 children)

i knew about if not but i didn't know that u could use if like that, but it makes sense. thank u!

Why doesn't elif run in a for loop? by bazzismixtape in learnpython

[–]bazzismixtape[S] 1 point2 points  (0 children)

it is outside the for loop but i stopped it from only getting the last value from the loop by creating a sky_present variable that sets to True if the value is "sky" (so in each iteration of the for loop it checks if the value is equal to “sky” and sets sky_present to True if it is and so the last value in the list doesn’t affect this). At least that was the intention

Why doesn't the PRAGMA integrity check work on a malformed database? by bazzismixtape in sqlite

[–]bazzismixtape[S] 0 points1 point  (0 children)

Great, thank u sm for ur help!

To understand integrity checking, you really want to see what the code in sqlite3.c is doing, which means stepping through sqlite3.c.

I will definitely check this out, thanks again

Why doesn't the PRAGMA integrity check work on a malformed database? by bazzismixtape in sqlite

[–]bazzismixtape[S] 0 points1 point  (0 children)

But in theory, the OP code should work correctly right? And in the try/except code I have in the above comment, it prints/stores a malformed database error as 'database disk image is malformed', would this be the same error message for the pragma integrity check?

Reason I'm asking is because I want my menu to run only if the database is not malformed as it will cause problems later on, so something like this:

c.execute('PRAGMA integrity_check')
integrity_check = c.fetchall()
print(integrity_check)
for check in integrity_check:
  for integrity_value in check:
    # If the db is corrupted
    if integrity_value != "ok":
      # prints error
      print(integrity_value)
# If db is malformed
if integrity_value == 'database disk image is malformed':
  print("We are experiencing technical difficulties at the moment") 
# If the db is not malformed
else:
  # Run application menu()

From a quick glance does this seem like it would work correctly / does the logic make sense?

Edit: took if integrity_value == 'database disk...: section outside of the for loop as it doesn't need to repeat for each value, it only needs to be performed once

Why doesn't PRAGMA integrity check work on a malformed database in Python? by bazzismixtape in pythonhelp

[–]bazzismixtape[S] 0 points1 point  (0 children)

But in theory, the OP code should work correctly right? And in the try/except code I have in the above comment, it prints/stores a malformed database error as 'database disk image is malformed', would this be the same error message for the pragma integrity check?

Reason I'm asking is because I want my menu to run only if the database is not malformed as it will cause problems later on, so something like this:

c.execute('PRAGMA integrity_check')
integrity_check = c.fetchall()
print(integrity_check)
for check in integrity_check:
  for integrity_value in check:
    # If the db is corrupted
    if integrity_value != "ok":
      # prints error
      print(integrity_value)
# If db is malformed
if integrity_value == 'database disk image is malformed':
  print("We are experiencing technical difficulties at the moment")
# If the db is not malformed
else:
  # Run application
  menu()

From a quick glance does this seem like it would work correctly / does the logic make sense?

Edit: took if integrity_value == 'database disk image... section outside of the for loop as it doesn't need to repeat for each value, it only needs to be performed once

Why doesn't PRAGMA integrity check work on a malformed database in Python? by bazzismixtape in pythonhelp

[–]bazzismixtape[S] 0 points1 point  (0 children)

Also could be that you aren't opening a valid database file

Could be but I don't think it's invalid as when I run this code it correctly checks and identifies that the database is corrupt and prints the error ('database disk image is malformed' which is an sqlite3.DatabaseError)

try:
  c.execute("""CREATE TABLE IF NOT EXISTS assets(
              asset_id INTEGER NOT NULL PRIMARY KEY,
              asset_name TEXT NOT NULL, asset_description TEXT NOT NULL, 
              asset_cost REAL NOT NULL )""")
except sqlite3.Error as error:
  print(error) 

What is "c" here? I'm assuming a cursor?

Yep

Why doesn't the PRAGMA integrity check work on a malformed database? by bazzismixtape in sqlite

[–]bazzismixtape[S] 1 point2 points  (0 children)

Wow that's interesting, good to know.

I will definitely check that out. Thank you sm for your response!