0

I am trying to test my code in different environments, test , prod ... I am planning to create a .env file and setting values for test and prod. but i have some declarations, line number 2 in sample below. i only need that when i run in local machine. how can i pass on an argument via command line, say main.py local and only then it executes at line else ignores it.

main.py

#connect to our cluster
1. from elasticsearch import Elasticsearch

#local mode only
2. ec2 = boto3.Session(profile_name='dev', region_name='eu-west-1').client('ec2')


if __name__ = "__main__"
ozil
  • 599
  • 7
  • 31

1 Answers1

1

You can use the sys library and sys.args like this:

import sys

x = sys.argv[1]
print(x)

use sys.argv[1] not 0 because 0 is actually the filename

Example

The Peeps191
  • 153
  • 1
  • 8