How to read an array with Python's ConfigParser

Introduction

When I looked it up, I thought, and I couldn't find an article in Japanese.

How to read an array with ConfigParser

1. Description in config.ini

I write it in a solid array.

[Foo]
fibs: [1,1,2,3,5,8,13]

The following is also possible.

[Foo]
fibs = [1,1,2,3,5,8,13]

2. Loading with a python program

If you read it with ConfigParser and process it with json.loads as it is, it will be an array.

import configparser
import json

config_ini = configparser.ConfigParser()
config_ini.read("config.ini", encoding='utf-8')

arr = json.loads(config.get("Foo","fibs"))
print(arr)  # [1, 1, 2, 3, 5, 8, 13]

Other

It was possible not only with numerical values but also with character strings.

reference

Recommended Posts

How to read an array with Python's ConfigParser
How to convert an array to a dictionary with Python [Application]
How to read an Excel file (.xlsx) with Pandas [Python]
How to read problem data with paiza
How to read a CSV file with Python 2/3
How to read PyPI
Add rows to an empty array with numpy
[Python] How to read excel file with pandas
How to read JSON
[Python] How to deal with pandas read_html read error
How to make an HTTPS server with Go / Gin
How to update with SQLAlchemy?
How to cast with Theano
How to Alter with SQLAlchemy?
How to separate strings with','
How to RDP with Fedora31
How to Delete with SQLAlchemy?
How to kill a process instantly with Python's Process Pool Executor
How to swap elements in an array in Python, and how to reverse an array.
How to enable Read / Write of net.Conn with context with golang
How to print characters as a table with Python's print function
How to run an app built with Python + py2app built with Anaconda
[Python Kivy] How to create an exe file with pyinstaller
I wanted to calculate an array with Sympy's subs method
How to output additional information when logging with python's logging module
How to cancel RT with tweepy
Python: How to use async with
How to use virtualenv with PowerShell
How to deal with imbalanced data
How to use Python's logging module
How to create an email user
How to read the SNLI dataset
How to get started with Scrapy
How to get started with Python
How to deal with DistributionNotFound errors
How to get started with Django
How to Data Augmentation with PyTorch
[Python] How to swap array values
How to use FTP with Python
How to calculate date with python
How to install mysql-connector with pip3
How to INNER JOIN with SQLAlchemy
How to use the ConfigParser module
How to install Anaconda with pyenv
How to use Python's Context Manager
How to authenticate with Django Part 2
How to authenticate with Django Part 3
How to make a string into an array or an array into a string in Python
How to make a command to read the configuration file with pyramid
How to create a heatmap with an arbitrary domain in Python
How to pass arguments using an instance with systemd's systemctl command
[Python] Explains how to use the format function with an example
[Django] How to read variables / constants defined in an external file
How to use an external editor for Python development with Grasshopper
How to do arithmetic with Django template
[Blender] How to set shape_key with script
How to title multiple figures with matplotlib
How to get parent id with sqlalchemy
How to make an artificial intelligence LINE bot with Flask + LINE Messaging API
How to read pydoc on python interpreter
python3 How to install an external module