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

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현