How could I extract the lengthy config from my controller/main code
Question: In my `controller.py` file, I have lots of actions to do.

And I also need the following config in dictionary format.

But these configs, `params_template`, `header`, .... are really distracting
me.

How could I save them in another Python file , and load them into current
`controller.py`

Thanks

    
    
      params_template="""
       {
        "__EVENTTARGET": "AvailabilitySearchInputSearchView$LinkButtonSubmit",
        "availabilitySearch.SearchInfo.SalesCode": null,
        "availabilitySearch.SearchInfo.SearchStations[0].DepartureStationCode": FROM_CITY,
        "availabilitySearch.SearchInfo.SearchStations[0].ArrivalStationCode": TO_CITY,
        "availabilitySearch.SearchInfo.SearchStations[0].DepartureDate": "11/28/2015",
        "availabilitySearch.SearchInfo.SearchStations[1].DepartureStationCode": null,
        "availabilitySearch.SearchInfo.SearchStations[1].ArrivalStationCode": null,
        "availabilitySearch.SearchInfo.SearchStations[1].DepartureDate": null,
        "availabilitySearch.SearchInfo.Direction": "Oneway",
        "fromDate": "1448640000000",
        "returnDate": null,
        "fromDate_1": null,
        "fromDate_2": null,
        "availabilitySearch.SearchInfo.AdultCount": "1",
        "availabilitySearch.SearchInfo.ChildrenCount": "0",
        "availabilitySearch.SearchInfo.InfantCount": "0",
        "availabilitySearch.SearchInfo.PromoCode": null
      }
      """
    
      headers = {
          'Origin': 'http://www.flyscoot.com',
          'Accept-Encoding': 'gzip, deflate',
          'Accept-Language': 'en-US,en;q=0.8',
          'Upgrade-Insecure-Requests': '1',
          'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36',
          'Content-Type': 'application/x-www-form-urlencoded',
          'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
          'Cache-Control': 'max-age=0',
          'Referer': 'http://www.flyscoot.com/index.php/en/',
          'Connection': 'keep-alive',
          'AlexaToolbar-ALX_NS_PH': 'AlexaToolbar/alxg-3.3',
      }
    
      ...
    


Answer: You can make a separate configuration file from the data you have. For
example, in a file `test.ini`, store your data like below:

    
    
    [headers]
    Origin: 'http://www.flyscoot.com'
    Accept-Encoding: 'gzip, deflate'
    Accept-Language: 'en-US,en;q=0.8'
    Upgrade-Insecure-Requests: '1'
    User-Agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36'
    Content-Type: 'application/x-www-form-urlencoded'
    Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
    Cache-Control: 'max-age=0'
    Referer: 'http://www.flyscoot.com/index.php/en/'
    Connection: 'keep-alive'
    AlexaToolbar-ALX_NS_PH: 'AlexaToolbar/alxg-3.3' 
    

Once you are done, you can now use
[ConfigParser](https://docs.python.org/2/library/configparser.html) to achieve
a very flexible control on your data.

If you apply the below code with above data, see what you can achieve:

    
    
    from ConfigParser import RawConfigParser
    
    parser= RawConfigParser()
    parser.read('demo.ini')
    
    print 
    #To retrieve all the sections 
    print parser.sections()
    
    print
    #to retrieve options of a section
    print parser.options('headers')
    
    #To get value of each option in a section
    for i in parser.options('headers'):
         print parser.get('headers',i) 
    

Output:

    
    
    ['headers']
    
    ['origin', 'accept-encoding', 'accept-language', 'upgrade-insecure-requests', 'user-agent', 'content-type', 'accept', 'cache-control', 'referer', 'connection', 'alexatoolbar-alx_ns_ph']
    
    'http://www.flyscoot.com'
    'gzip, deflate'
    'en-US,en;q=0.8'
    '1'
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36'
    'application/x-www-form-urlencoded'
    'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
    'max-age=0'
    'http://www.flyscoot.com/index.php/en/'
    'keep-alive'
    'AlexaToolbar/alxg-3.3'
    

Read more about ConfigParser from
[Here](https://wiki.python.org/moin/ConfigParserExamples). Hope this helps :)

