Windows batch script to read an .ini file

Here’s a command file (ini.cmd) you can use to extract the relevant values: @setlocal enableextensions enabledelayedexpansion @echo off set file=%~1 set area=[%~2] set key=%~3 set currarea= for /f “usebackq delims=” %%a in (“!file!”) do ( set ln=%%a if “x!ln:~0,1!”==”x[” ( set currarea=!ln! ) else ( for /f “tokens=1,2 delims==” %%b in (“!ln!”) do ( set … Read more

How to configure PIP per config file to use a proxy (with authentification)?

Here are the steps how to configure proxy (with auth.) in pip’s config file (pip.ini) (if it does not already exist) Create a folder named ‘pip’ and inside it a file named ‘pip.ini’ as described here: https://pip.pypa.io/en/stable/user_guide/#config-file (location an name may differ per platform – e.g. on Windows it’s %APPDATA%\pip\pip.ini) edit pip.ini file and add … Read more

Read all the contents in ini file into dictionary with Python

I suggest subclassing ConfigParser.ConfigParser (or SafeConfigParser, &c) to safely access the “protected” attributes (names starting with single underscore — “private” would be names starting with two underscores, not to be accessed even in subclasses…): import ConfigParser class MyParser(ConfigParser.ConfigParser): def as_dict(self): d = dict(self._sections) for k in d: d[k] = dict(self._defaults, **d[k]) d[k].pop(‘__name__’, None) return d … Read more

How to set boolean values in an INI configuration file?

There’s no spec for INI files, but for whatever it’s worth, I’ll list the behaviour of a few implementations from languages I know. Python’s built-in configparser module offers a getboolean that behaves as follows: the accepted values … are ‘1’, ‘yes’, ‘true’, and ‘on’, which cause this method to return True, and ‘0’, ‘no’, ‘false’, … Read more

create ini file, write values in PHP

Found following code snippet from the comments of the PHP documentation: function write_ini_file($assoc_arr, $path, $has_sections=FALSE) { $content = “”; if ($has_sections) { foreach ($assoc_arr as $key=>$elem) { $content .= “[“.$key.”]\n”; foreach ($elem as $key2=>$elem2) { if(is_array($elem2)) { for($i=0;$i<count($elem2);$i++) { $content .= $key2.”[] = \””.$elem2[$i].”\”\n”; } } else if($elem2==””) $content .= $key2.” = \n”; else $content … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)