Questions & Answers
39
votes
1
answers
1503
views
How to handle keyboard interrupts in Python
My script should clean up when user presses Ctrl+C. How do I handle this?
47
votes
1
answers
980
views
How to use Python multiprocessing for parallel tasks
My script is CPU-bound and slow. How can I use multiple cores?
37
votes
1
answers
241
views
How to send emails in Python
I need to send automated emails from my Python script. How do I do this?
14
votes
1
answers
361
views
How to create and use Python decorators
I see @decorator syntax in Python. How do I create my own decorator?
6
votes
1
answers
721
views
How to download files in Python
What is the correct way to download files from URLs in Python?
23
votes
1
answers
210
views
How to use Python logging module properly
I want to replace print statements with proper logging. How do I set it up?
13
votes
1
answers
1835
views
How to create a class in Python
What is the proper way to define a class with methods and properties?
11
votes
1
answers
712
views
How to read CSV files in Python
What is the best way to read and process CSV files?
28
votes
1
answers
1402
views
How to format strings in Python
What are the different ways to format strings in Python?
3
votes
1
answers
477
views
How to remove duplicates from a list in Python
I have a list with duplicate values. How do I remove them?
33
votes
1
answers
496
views
How to check if file exists in Python
I need to check if a file or directory exists before processing it.
7
votes
1
answers
532
views
How to merge two dictionaries in Python
What is the cleanest way to combine two dictionaries?
30
votes
1
answers
1165
views
How to sort a list of dictionaries in Python
I have a list of dictionaries and want to sort by a specific key.
36
votes
1
answers
1675
views
How to iterate over dictionary in Python
What is the best way to loop through a dictionary keys and values?
12
votes
1
answers
824
views
How to create custom Django management commands
I need to create a custom command that I can run with manage.py. How do I create one?
36
votes
1
answers
1564
views
How to work with environment variables in Python
How do I read environment variables in Python and set default values if they do not exist?
38
votes
1
answers
1230
views
How to use context managers (with statement) in Python
I see "with" statements used in Python. What are context managers and how do I create my own?