Tuesday, 12 August 2025

Setting environmental variables using .env file in Python

 STEP-1 - Finding the Root path of your python code


import os
# Get the current working directory
cwd = os.getcwd()
print(cwd)

Output




STEP-2 -Creating Env files

  • After getting root path folder, create a file names .env file in that folder as shown below






STEP-3 -Entering credential details in .env File

  • you can enter all the secure details in env file as shown below.



No comments:

Post a Comment