-2

I have my config file in the format given below.

[Connection]
Oracle=Some Value
MySql=Some Value

[Queries]
productionTable1=Somevalue
productionTable2=Somevalue

Now I want to write a program file which would take the connection and table name as input and fetch me the corresponding values from the config file.

I wrote a code like this :

import sys
import configparser
config = configparser.ConfigParser()
config.sections()
config.read('mytest.ini')
config.sections()
connection_name=sys.argv[0]
load_query=sys.argv[1]
Myconnection=config.get("Connections","{}".format(connection_name))
My_load_query=config.get("Queries","{}".format(load_query))
print(Myconnection)
print(My_load_query)

But when I run the command "python3 test3.py Oracle productionTable1"

I get the below error:

During handling of the above exception, another exception occurred:

configparser.NoOptionError: No option 'test3.py' in section: 'Connections'

So could anyone help me where I have gone wrong.

buran
  • 13,682
  • 10
  • 36
  • 61
Akcs004
  • 3
  • 4

1 Answers1

0

As mentioned above, the first argument (sys.argv[0]) is always the name of the file. So you need to use sys.argv[1] and sys.argv[2] to get to your values.

EgorLu
  • 98
  • 4