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

                      How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                      Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?