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?
cloud_arch Platinum asked 1 week, 2 days ago
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?
youssef_net Platinum asked 1 week, 2 days ago
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?
db_admin Silver asked 1 week, 2 days ago
45
votes
1
answers
1143
views

How to work with SQLite in Python

I need a simple database for my Python project. How do I use SQLite?
layla_web Bronze asked 1 week, 2 days ago
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?
noor_code Gold asked 1 week, 2 days ago
6
votes
1
answers
721
views

How to download files in Python

What is the correct way to download files from URLs in Python?
web_developer Platinum asked 1 week, 2 days ago
13
votes
1
answers
794
views

How to parse XML in Python

I need to read and parse XML files in Python. What is the best approach?
layla_web Bronze asked 1 week, 2 days ago
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?
fatima_dev Silver asked 1 week, 2 days ago
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?
noor_code Gold asked 1 week, 2 days ago
11
votes
1
answers
712
views

How to read CSV files in Python

What is the best way to read and process CSV files?
hassan_ops Bronze asked 1 week, 2 days ago
28
votes
1
answers
1402
views

How to format strings in Python

What are the different ways to format strings in Python?
devops_guru Gold asked 1 week, 2 days ago
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?
sysadmin Silver asked 1 week, 2 days ago
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.
youssef_net Platinum asked 1 week, 2 days ago
7
votes
1
answers
532
views

How to merge two dictionaries in Python

What is the cleanest way to combine two dictionaries?
web_developer Platinum asked 1 week, 2 days ago
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.
hassan_ops Bronze asked 1 week, 2 days ago
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?
security_pro Bronze asked 1 week, 2 days ago
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?
python_dev Platinum asked 1 week, 2 days ago
35
votes
1
answers
310
views

How to use regular expressions in Python

I need to extract data from text using patterns. How do I use regex in Python?
noor_code Gold asked 1 week, 2 days ago
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?
linux_expert Bronze asked 1 week, 2 days ago
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?
db_admin Silver asked 1 week, 2 days ago