<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: python how to call configuration file controlling am having two configuration file one is by default configuration another real time config file? in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/python-how-to-call-configuration-file-controlling-am-having/m-p/232894#M64564</link>
    <description>&lt;A rel="user" href="https://community.cloudera.com/users/12747/swathidataengineer.html" nodeid="12747"&gt;@swathi thukkaraju&lt;/A&gt;&lt;P&gt;You can use the &lt;A href="https://docs.python.org/3/library/stdtypes.html#dict.update"&gt;dict.update() method&lt;/A&gt;: read the default config first to a dictionary, then read your config and call default.update(yours). &lt;/P&gt;&lt;P&gt;But keep an eye on the fact that your two configs are not compatible: in your config "path_details" and "db_details" are the children of "parser_config", while in the default config they are on the same level. If we assume that the original config is correct, then you should update swathi_configure.json like this:&lt;/P&gt;&lt;PRE&gt;[{
  "parser_config": {
    "vista": {
      "Parser_info": {
        "module_name": "A",
        "class_name": "a",
        "standardformat1": {
          "transaction": "filename",
          "terminal": "filenme2",
          "session": "filename3"
        }
      }
    }
  },
  "path_details": {
    "parent_path": "wasbs://XXXX@XXXXXstorage.blob.core.windows.net/tenantShortName/"
  },
  "db_details": {
    "datawarehouse_url": "",
    "datawarehouse_username": "",
    "datawarehouse_password": ""
  }
}]
&lt;/PRE&gt;&lt;P&gt;With these two files the following code does what you want:&lt;/P&gt;&lt;PRE&gt;import json
from pprint import pprint

with open('config.json') as default_file, \
     open('swathi_configure.json') as current_file:

    # [0]: take the first and only item from your list
    # If you have more items, use a for loop
    default = json.load(default_file)[0]
    current = json.load(current_file)[0]
    default.update(current)

    # default is your merged config now
    pprint(default)
&lt;/PRE&gt;</description>
    <pubDate>Tue, 11 Jul 2017 19:36:47 GMT</pubDate>
    <dc:creator>gnovak</dc:creator>
    <dc:date>2017-07-11T19:36:47Z</dc:date>
    <item>
      <title>python how to call configuration file controlling am having two configuration file one is by default configuration another real time config file?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/python-how-to-call-configuration-file-controlling-am-having/m-p/232893#M64563</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hi friends,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;
&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In python how to control  configuration files  am having two configuration file one is by default configuration another real time config file if the real time config file having some object details some defined as empty  if any defined values are empty it should take from default configure json file  otherwise it not empty should take from current config json file??&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;step1: am having on config json file  as shown below:&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;[{
"parser_config":&lt;/P&gt;&lt;P&gt; {
"vista": {
"Parser_info": {
"module_name": "A",
"class_name": "a",
"standardformat1": {
"transaction": "filename",
"terminal": "filenme2",
"session": "filename3"
}
}
},
"Agilis": {
"Parser_info": {
"module_name": "B",
"class_name": "b",
"standardformat1": {
"transaction": "filename",
"terminal": "filenme2",
"session": "filename3"
}
}
}
}, &lt;/P&gt;&lt;P&gt;"merger_processor_config": {
"Merger": {
"standardformat1": {
"vista": {
"file_names": ["transaction", "terminal"],
"parser_output_join_columns": ["TERMINALID"]
},
"commander": {
"file_names": ["transaction", "terminal"],
"parser_output_join_columns": ["TERMINALID"]
}
},
"source_merge_join_columns": [
"TERMINALID",
"BUSINESSDATE",
"TXNSEQNO"
],
"input_path": "/tenantShortName/yyyyMMdd/",
"primary_datatype": "Vista",
"module_name": "A",
"class_name": "a",
"merged_output": "true",
"merger_output_filepath": "/customer1/MergerOutput/"
},
"Processor": {
"terminal_transaction_fact_processor": {
"module_name": "nme1",
"class_name": "nme2",
"usecase_processor": {
"usecase1": {
"module_name": "nme1",
"class_name": "nme2"
}
}
}
}
},
"path_details": {
"parent_path": "wasbs://XXXX@XXXXXstorage.blob.core.windows.net/tenantShortName/"
},
"db_details": {
"datawarehouse_url": "",
"datawarehouse_username": "",
"datawarehouse_password": ""
}
}]&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;step2: am calling that configuration file objects  here&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;import json&lt;/P&gt;&lt;P&gt;from pprint import &lt;U&gt;pprint&lt;/U&gt;&lt;/P&gt;&lt;P&gt;with open(&lt;EM&gt;'Config.json'&lt;/EM&gt;) as data_file: &lt;/P&gt;&lt;P&gt; data = json.load(data_file)&lt;/P&gt;&lt;P&gt;#&lt;U&gt;val&lt;/U&gt; = data["parser_config"]&lt;/P&gt;&lt;P&gt;for val in data:&lt;/P&gt;&lt;P&gt;print&lt;EM&gt;"parser_config ====="&lt;/EM&gt;,val[&lt;EM&gt;"parser_config"&lt;/EM&gt;][&lt;EM&gt;"vista"&lt;/EM&gt;]&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;step3: If am having  another swathi_configure json file in that file am having few values of objects as shown in below &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;[{
"parser_config": {
"vista": {
"Parser_info": {
"module_name": "A",
"class_name": "a",
"standardformat1": {
"transaction": "filename",
"terminal": "filenme2",
"session": "filename3"
}
}
},&lt;/P&gt;&lt;P&gt;"path_details": { "parent_path": "wasbs://XXXX@XXXXXstorage.blob.core.windows.net/tenantShortName/" }, "db_details": { "datawarehouse_url": "", "datawarehouse_username": "", "datawarehouse_password": "" } }]&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;
&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;step4: In the config file having only three objects parser_config,path_details,db_details  remaining objects are not existed  not existed fields to be from  default config file if any objects not existed in current config file it should go for default config file and collects like a trace back.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If the current config file having objects it should take current of objects in from current config json file&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;how to write a code to control on &lt;EM&gt;config.json&amp;amp; &lt;/EM&gt;swathi_configure.json&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;please help today i need to complete this task give me how to solve this problem&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;
&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thanks in advance&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;swathi.tukkaraju&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 17:42:23 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/python-how-to-call-configuration-file-controlling-am-having/m-p/232893#M64563</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2017-07-10T17:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: python how to call configuration file controlling am having two configuration file one is by default configuration another real time config file?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/python-how-to-call-configuration-file-controlling-am-having/m-p/232894#M64564</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/12747/swathidataengineer.html" nodeid="12747"&gt;@swathi thukkaraju&lt;/A&gt;&lt;P&gt;You can use the &lt;A href="https://docs.python.org/3/library/stdtypes.html#dict.update"&gt;dict.update() method&lt;/A&gt;: read the default config first to a dictionary, then read your config and call default.update(yours). &lt;/P&gt;&lt;P&gt;But keep an eye on the fact that your two configs are not compatible: in your config "path_details" and "db_details" are the children of "parser_config", while in the default config they are on the same level. If we assume that the original config is correct, then you should update swathi_configure.json like this:&lt;/P&gt;&lt;PRE&gt;[{
  "parser_config": {
    "vista": {
      "Parser_info": {
        "module_name": "A",
        "class_name": "a",
        "standardformat1": {
          "transaction": "filename",
          "terminal": "filenme2",
          "session": "filename3"
        }
      }
    }
  },
  "path_details": {
    "parent_path": "wasbs://XXXX@XXXXXstorage.blob.core.windows.net/tenantShortName/"
  },
  "db_details": {
    "datawarehouse_url": "",
    "datawarehouse_username": "",
    "datawarehouse_password": ""
  }
}]
&lt;/PRE&gt;&lt;P&gt;With these two files the following code does what you want:&lt;/P&gt;&lt;PRE&gt;import json
from pprint import pprint

with open('config.json') as default_file, \
     open('swathi_configure.json') as current_file:

    # [0]: take the first and only item from your list
    # If you have more items, use a for loop
    default = json.load(default_file)[0]
    current = json.load(current_file)[0]
    default.update(current)

    # default is your merged config now
    pprint(default)
&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jul 2017 19:36:47 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/python-how-to-call-configuration-file-controlling-am-having/m-p/232894#M64564</guid>
      <dc:creator>gnovak</dc:creator>
      <dc:date>2017-07-11T19:36:47Z</dc:date>
    </item>
  </channel>
</rss>

