Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set a value to None with ConfigParser?

I'm using ConfigParser in Python 2.7 to read from a config file and I'm wondering how to read a value such that it's set to the constant None in Python.

Currently, my code is as follows:

config.set("Test Series Parameters", "Test Series Parameter", None)

However, this shows up as Test Series Parameter = "None" (as a string).

like image 796
Parth Avatar asked Feb 17 '12 21:02

Parth


People also ask

What is Configparser Configparser ()?

ConfigParser is a Python class which implements a basic configuration language for Python programs. It provides a structure similar to Microsoft Windows INI files. ConfigParser allows to write Python programs which can be customized by end users easily.

What is config () in Python?

A Python configuration file is a pure Python file that populates a configuration object. This configuration object is a Config instance.

What is .ini file in Python?

An INI file is a configuration file for computer software that consists of a text-based content with a structure and syntax comprising key–value pairs for properties, and sections that organize the properties.


1 Answers

According to the 2.7.2 docs:

When allow_no_value is true (default: False), options without values are accepted; the value presented for these is None. Does that help?

like image 83
Carlos Avatar answered Oct 14 '22 07:10

Carlos