Python config parser to get all the values from a section?How to return multiple values from a function?How to get the current time in PythonHow do you get the logical xor of two variables in Python?Getting the last element of a list in PythonHow do I get the number of elements in a list in Python?Why can't Python parse this JSON data?Find all files in a directory with extension .txt in PythonWhy is reading lines from stdin much slower in C++ than Python?How to remove a key from a Python dictionary?Get unique values from a list in python

Changing the PK column of a data extension without completely recreating it

Boss making me feel guilty for leaving the company at the end of my internship

How to make this Scala method return the same generic as the input?

ISP is not hashing the password I log in with online. Should I take any action?

Can a 40amp breaker be used safely and without issue with a 40amp device on 6AWG wire?

What publication claimed that Michael Jackson died in a nuclear holocaust?

Does WiFi affect the quality of images downloaded from the internet?

I sent an angry e-mail to my interviewers about a conflict at my home institution. Could this affect my application?

What did the 8086 (and 8088) do upon encountering an illegal instruction?

Do Veracrypt encrypted volumes have any kind of brute force protection?

Can I use 220 V outlets on a 15 ampere breaker and wire it up as 110 V?

If absolute velocity does not exist, how can we say a rocket accelerates in empty space?

Tiffeneau–Demjanov rearrangement products

Harley Davidson clattering noise from engine, backfire and failure to start

Why would a home insurer offer a discount based on credit score?

Is there a radar system monitoring the UK mainland border?

Why is my Taiyaki (Cake that looks like a fish) too hard and dry?

Am I being scammed by a sugar daddy?

Plot vectors as sums of vectors along the axes

How can religions without a hell discourage evil-doing?

How do I type a hyphen in iOS 12?

Commencez à vous connecter -- I don't understand the phrasing of this

Purpose of cylindrical attachments on Power Transmission towers

Why would a car salesman tell me not to get my credit pulled again?



Python config parser to get all the values from a section?


How to return multiple values from a function?How to get the current time in PythonHow do you get the logical xor of two variables in Python?Getting the last element of a list in PythonHow do I get the number of elements in a list in Python?Why can't Python parse this JSON data?Find all files in a directory with extension .txt in PythonWhy is reading lines from stdin much slower in C++ than Python?How to remove a key from a Python dictionary?Get unique values from a list in python






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








37















I want to get all the values from a section using config parser



I used this but it gives only the first value



def ConfigSectionMap(section):
dict1 =
options = Config.options(section)
for option in options:
try:
dict1[option] = Config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1


Config = ConfigParser.ConfigParser()
Config.read("/etc/harvest.conf")
print ConfigSectionMap("files").values()









share|improve this question



















  • 4





    Your return is not properly indented and your function returns in the first iteration of the for loop. Remove two spaces.

    – Chewie
    Dec 20 '11 at 16:27

















37















I want to get all the values from a section using config parser



I used this but it gives only the first value



def ConfigSectionMap(section):
dict1 =
options = Config.options(section)
for option in options:
try:
dict1[option] = Config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1


Config = ConfigParser.ConfigParser()
Config.read("/etc/harvest.conf")
print ConfigSectionMap("files").values()









share|improve this question



















  • 4





    Your return is not properly indented and your function returns in the first iteration of the for loop. Remove two spaces.

    – Chewie
    Dec 20 '11 at 16:27













37












37








37


1






I want to get all the values from a section using config parser



I used this but it gives only the first value



def ConfigSectionMap(section):
dict1 =
options = Config.options(section)
for option in options:
try:
dict1[option] = Config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1


Config = ConfigParser.ConfigParser()
Config.read("/etc/harvest.conf")
print ConfigSectionMap("files").values()









share|improve this question
















I want to get all the values from a section using config parser



I used this but it gives only the first value



def ConfigSectionMap(section):
dict1 =
options = Config.options(section)
for option in options:
try:
dict1[option] = Config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1


Config = ConfigParser.ConfigParser()
Config.read("/etc/harvest.conf")
print ConfigSectionMap("files").values()






python parsing configparser






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 19 '18 at 4:27









sk8forether

12018




12018










asked Dec 20 '11 at 16:14









RishabhRishabh

2,28343662




2,28343662







  • 4





    Your return is not properly indented and your function returns in the first iteration of the for loop. Remove two spaces.

    – Chewie
    Dec 20 '11 at 16:27












  • 4





    Your return is not properly indented and your function returns in the first iteration of the for loop. Remove two spaces.

    – Chewie
    Dec 20 '11 at 16:27







4




4





Your return is not properly indented and your function returns in the first iteration of the for loop. Remove two spaces.

– Chewie
Dec 20 '11 at 16:27





Your return is not properly indented and your function returns in the first iteration of the for loop. Remove two spaces.

– Chewie
Dec 20 '11 at 16:27












2 Answers
2






active

oldest

votes


















93














Make it a dict:



dict(Config.items('Section'))





share|improve this answer
































    7














    You can make it a list if ordering is important



    list(Config.items('Section'))





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8578430%2fpython-config-parser-to-get-all-the-values-from-a-section%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      93














      Make it a dict:



      dict(Config.items('Section'))





      share|improve this answer





























        93














        Make it a dict:



        dict(Config.items('Section'))





        share|improve this answer



























          93












          93








          93







          Make it a dict:



          dict(Config.items('Section'))





          share|improve this answer















          Make it a dict:



          dict(Config.items('Section'))






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 16 '16 at 14:20

























          answered Dec 20 '11 at 16:19









          Niclas NilssonNiclas Nilsson

          3,8032437




          3,8032437























              7














              You can make it a list if ordering is important



              list(Config.items('Section'))





              share|improve this answer



























                7














                You can make it a list if ordering is important



                list(Config.items('Section'))





                share|improve this answer

























                  7












                  7








                  7







                  You can make it a list if ordering is important



                  list(Config.items('Section'))





                  share|improve this answer













                  You can make it a list if ordering is important



                  list(Config.items('Section'))






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 17 '17 at 2:35









                  jithu83jithu83

                  16829




                  16829



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8578430%2fpython-config-parser-to-get-all-the-values-from-a-section%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript