Tagged Questions
0
votes
0answers
19 views
How can I verify if an input is either a json string or a file containing json in python? [closed]
I've got a small module that reads JSON strings and does something with the data they contain. It's designed to accept both JSON strings and files that contain JSON. Consider this code:
import os
...
0
votes
1answer
44 views
Is 'try / finally' the best way for me to handle (and close) this long-running IMAP4 connection?
I'm writing a script to archive email messages from one IMAP folder to another. It looks, more or less, like the following. I've obfuscated about 30 lines unrelated to this question:
import imaplib
...
2
votes
2answers
45 views
Wrapping an Exception with context-management, using the with statement
Before I try to make this work, I wondered if anyone had tried this, whether it was a good idea or not, etc.
I find myself doing this a lot:
if some_result is None:
try:
raise ...
2
votes
3answers
115 views
I think I'm not using Try Except properly in this Python code
Please offer some advice for this code. It all works, but I know that its messy and I don't think the Exception catching is doing what I want it to. Thanks in advance for any and all advice...
def ...
1
vote
1answer
145 views
LPTHW - ex48 - Handling exceptions and unit testing
This is my solution to the exercise 48 of Learn Python the hard way by Zed Shaw. Please visit the link for testing suite and requirements.
I'm worried about my the word banks I have created (COMPASS, ...
1
vote
1answer
135 views
Learning Simple Operating System Tools: Experienced Tips?
Operating system code, I've noticed, has two outstanding properties:
1. It's everywhere, and vitally important to functional software
2. It has *lots* of exceptions.
Please give me some pointers on ...