Ad
How To Read Configurations Parameters From An INI File?
I want to set some paths of excel files in the INI file to be read by my code in Python. Can you please tell me how to call them?
In my ini
file I have something like this:
[common]
default_path = "C:/Users/XX/Desktop/Bk.xlsx/"
Ad
Answer
- For loading excel file install xlrd from pypi.
Command to install xlrd module : pip install xlrd
In config.ini dont need " so:
[general]
default_path = C:/Users/XX/Desktop/Bk.xlsx/
sample code:
import xlrd
import configparser
#Loading config
config = configparser.ConfigParser()
config.read("config.ini")
Excel_PATH = config["general"]["default_path"]
# Reading an excel file using Python
wb = xlrd.open_workbook(Excel_PATH)
sheet = wb.sheet_by_index(0)
# For row 0 and column 0
sheet.cell_value(0, 0)
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad