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;
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
add a comment |
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
4
Yourreturn
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
add a comment |
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
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
python parsing configparser
edited Jul 19 '18 at 4:27
sk8forether
12018
12018
asked Dec 20 '11 at 16:14
RishabhRishabh
2,28343662
2,28343662
4
Yourreturn
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
add a comment |
4
Yourreturn
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
add a comment |
2 Answers
2
active
oldest
votes
Make it a dict:
dict(Config.items('Section'))
add a comment |
You can make it a list if ordering is important
list(Config.items('Section'))
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Make it a dict:
dict(Config.items('Section'))
add a comment |
Make it a dict:
dict(Config.items('Section'))
add a comment |
Make it a dict:
dict(Config.items('Section'))
Make it a dict:
dict(Config.items('Section'))
edited Feb 16 '16 at 14:20
answered Dec 20 '11 at 16:19
Niclas NilssonNiclas Nilsson
3,8032437
3,8032437
add a comment |
add a comment |
You can make it a list if ordering is important
list(Config.items('Section'))
add a comment |
You can make it a list if ordering is important
list(Config.items('Section'))
add a comment |
You can make it a list if ordering is important
list(Config.items('Section'))
You can make it a list if ordering is important
list(Config.items('Section'))
answered Nov 17 '17 at 2:35
jithu83jithu83
16829
16829
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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