4

how would one use python config parser to get every entry under a single section and write to a new file without actually specifying each entry

for example how would I go about getting everything under section "testing" and write to a new file without using config.get and listing every entry?

config file

[testing]
test1=test23452
test2=test45235
test3=test54524
[donotneed]
something1=something
something2=somethingelse

I've tried the following just for testing purposes

config = ConfigParser.ConfigParser()
    config.read(configFilePath)
    testing = {k:v for k,v in config.items('testing')}
    for x in testing:
        print (x)

but it's only printing the following

test1
test3
test2

and not everything in that section, I need it to give me

test1=test23452
test2=test45235
test3=test54524
Ranga Sarin
  • 169
  • 1
  • 5
  • 14

1 Answers1

2

for x in testing will just parse the keys of the dictionary testing.

You need:

for x in testing.items():
  print x[0] + '=' + x[1]
colidyre
  • 4,170
  • 12
  • 37
  • 53
Abhimanyu singh
  • 397
  • 3
  • 9