Closing file opened by ConfigParser

后端 未结 4 1219
北恋
北恋 2020-12-31 08:35

I have the following:

config = ConfigParser()
config.read(\'connections.cfg\')
sections = config.sections()

How can I close the file opened

4条回答
  •  自闭症患者
    2020-12-31 09:36

    The difference between ConfigParser and RawConfigParser is that ConfigParser will attempt to "magically" expand references to other config variables, like so:

    x = 9000 %(y)s
    y = spoons
    

    In this case, x will be 9000 spoons, and y will just be spoons. If you need this expansion feature, the docs recommend that you instead use SafeConfigParser. I don't know what exatly the difference between the two is. If you don't need the expansion (you probably don't) just need RawConfigParser.

提交回复
热议问题