error-handling

Assertion Error: Custom Exception not raised

Assertion Error: Custom Exception not raised Question: I am trying to write unittests for a function I wrote that includes a try/except block. I have raised a custom exception if my string contains less than 3 characters. I wanted to test that the error gets raised when inputting a string less than 3 characters long. …

Total answers: 2

Unable to find vcvarsall.bat (Unsolved for 2022 version, Python)

Unable to find vcvarsall.bat (Unsolved for 2022 version, Python) Question: I’ve been trying to instsall pgzero library for python, but however it keeps giving me an error: "unable to find vcvarsall.bat " I have been searching over StackOverflow, it shows up how to fix it for 2017 version by installing Microsoft building tools, i did …

Total answers: 1

Python unittest that at least one exception is raised

Python unittest that at least one exception is raised Question: Is there a way to get unittest standard library to check for multiple exceptions? Obviously assertRaises works for a single exception: How do you test that a Python function throws an exception? But I want to test whether at least one error is raised. This …

Total answers: 1

Python and SQLite: insert into table by input

Python and SQLite: insert into table by input Question: enter image description here I am doing this but it still gives me this Error I am trying to insert data by input into the table Asked By: Suliman || Source Answers: Try this: cr.execute(f"INSERT INTO Family VALUES(‘{name}’,{age},'{Hobby}’)") Answered By: user56700 Python example to insert a …

Total answers: 2

How to ignore corrupted files?

How to ignore corrupted files? Question: How to loop through a directory in Python and open wave files that are good whilst ignoring bad (corrupted) ones? I want to open various wave files from a directory. However, some of these files may be corrupted, some may not be to specification. In particular there will be …

Total answers: 2

my code Wont run any line other than the bottom line of code

My code Wont run any line other than the bottom line of code Question: I was using the program fine and the bot and commands all worked as intended however after restarting the program only the code at the bottom would work, i.e if I deleted the slap section the punch would work but no …

Total answers: 1

Nested dictionary incorrectly populating all top level key-value pairs with same values

Nested dictionary incorrectly populating all top level key-value pairs with same values Question: I am having a strange issue where indexing a nested dictionary correctly results in the same value being assigned for all top level keys (k’s). Below is the whole chunk of code. scores_by_n = dict.fromkeys(range(3, 5 + 1), {}) for k in …

Total answers: 2

try except block prints 'hello'

try except block prints 'hello' Question: I have a perculiar problem. I’m using the extract_msg package to analyse a bunch of .msg files. The package results in an NotImplementedError error when the .msg file contains attachtments. I’m using a try-except block to catch this error, but for some weird reason its prints "hello" for every …

Total answers: 1