We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 550eac7 commit 4bf4ebdCopy full SHA for 4bf4ebd
1 file changed
Day-05/README.md
@@ -5,13 +5,21 @@ Here's a comprehensive guide to working with environment variables in Python.
5
6
using below command we should export env variable to linux/mac
7
```
8
+# Add to ~/.bashrc, ~/.zshrc, or ~/.profile
9
+export API_KEY="your_api_key_here"
10
export DB_HOST="localhost"
11
12
13
In the code we call env variable by using `os.getenv`
14
15
import os
16
-## ** Simple get with optional default **
-api_key = os.getenv('API_KEY', 'default-key')
17
+# Method 1: os.environ (raises KeyError if missing)
18
+api_key = os.environ['API_KEY']
19
+
20
+# Method 2: os.getenv() (safer, returns None if missing)
21
+db_host = os.getenv('DB_HOST')
22
23
+# Method 3: With default value
24
+db_port = os.getenv('DB_PORT', '5432') # Default to 5432 if not set
25
0 commit comments