<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	
	>
<channel>
	<title>
	Comments on: Why bother with python and config files?	</title>
	<atom:link href="https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/</link>
	<description>Blog of Rob Galanakis (@robgalanakis)</description>
	<lastBuildDate>Sat, 21 Jul 2012 22:13:14 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.4.1</generator>
	<item>
		<title>
		By: Piotr Dobrogost		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-42196</link>

		<dc:creator><![CDATA[Piotr Dobrogost]]></dc:creator>
		<pubDate>Sat, 21 Jul 2012 22:13:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-42196</guid>

					<description><![CDATA[The opposite view: &quot;Python is Not a Configuration File Format&quot; by Roberto Alsina - http://lateral.netmanagers.com.ar/weblog/posts/python-is-not-a-configuration-file-format.html]]></description>
			<content:encoded><![CDATA[<p>The opposite view: &#8220;Python is Not a Configuration File Format&#8221; by Roberto Alsina &#8211; <a href="http://lateral.netmanagers.com.ar/weblog/posts/python-is-not-a-configuration-file-format.html" rel="nofollow ugc">http://lateral.netmanagers.com.ar/weblog/posts/python-is-not-a-configuration-file-format.html</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Piotr Dobrogost		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-42179</link>

		<dc:creator><![CDATA[Piotr Dobrogost]]></dc:creator>
		<pubDate>Sat, 21 Jul 2012 20:26:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-42179</guid>

					<description><![CDATA[&lt;a href=&quot;#comment-31246&quot; rel=&quot;nofollow&quot;&gt;@Ken Whitesell&lt;/a&gt; 

The first 3 rules are being obeyed the same for configuration kept in python files as with files in any other format.]]></description>
			<content:encoded><![CDATA[<p><a href="#comment-31246" rel="nofollow">@Ken Whitesell</a> </p>
<p>The first 3 rules are being obeyed the same for configuration kept in python files as with files in any other format.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Piotr Dobrogost		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-42159</link>

		<dc:creator><![CDATA[Piotr Dobrogost]]></dc:creator>
		<pubDate>Sat, 21 Jul 2012 19:06:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-42159</guid>

					<description><![CDATA[&lt;a href=&quot;#comment-31367&quot; rel=&quot;nofollow&quot;&gt;@Thomas Kluyver&lt;/a&gt; 

After reading this comment I asked &quot;How to save Python in-memory dictionary to a file as a Python source code?&quot; question at Stackoverflow (http://stackoverflow.com/q/11594304/95735).

Ignacio Vazquez-Abrams answered:
&quot;Assuming it uses only &quot;basic&quot; Python types, you can write out the repr() of the structure, and then use ast.literal_eval() to read it back in after.&quot;

It looks like saving a config dict is rather easy...]]></description>
			<content:encoded><![CDATA[<p><a href="#comment-31367" rel="nofollow">@Thomas Kluyver</a> </p>
<p>After reading this comment I asked &#8220;How to save Python in-memory dictionary to a file as a Python source code?&#8221; question at Stackoverflow (<a href="http://stackoverflow.com/q/11594304/95735" rel="nofollow ugc">http://stackoverflow.com/q/11594304/95735</a>).</p>
<p>Ignacio Vazquez-Abrams answered:<br />
&#8220;Assuming it uses only &#8220;basic&#8221; Python types, you can write out the repr() of the structure, and then use ast.literal_eval() to read it back in after.&#8221;</p>
<p>It looks like saving a config dict is rather easy&#8230;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Adam Skutt		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-33135</link>

		<dc:creator><![CDATA[Adam Skutt]]></dc:creator>
		<pubDate>Fri, 29 Jun 2012 20:01:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-33135</guid>

					<description><![CDATA[As I already mentioned, there are several libraries out there that parse INI files and do type marshalling.  cherrypy.reprconf is one.  ConfigObj is another.  If that&#039;s your killer feature, it is trivial to have.]]></description>
			<content:encoded><![CDATA[<p>As I already mentioned, there are several libraries out there that parse INI files and do type marshalling.  cherrypy.reprconf is one.  ConfigObj is another.  If that&#8217;s your killer feature, it is trivial to have.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Chris Graham		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-32989</link>

		<dc:creator><![CDATA[Chris Graham]]></dc:creator>
		<pubDate>Fri, 29 Jun 2012 17:34:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-32989</guid>

					<description><![CDATA[&lt;blockquote cite=&quot;#comment-content-31701&quot;&gt;
&lt;strong&gt;&lt;a href=&quot;#comment-31701&quot; rel=&quot;nofollow&quot;&gt;Adam Skutt&lt;/a&gt; :&lt;/strong&gt;
    I’m not sure why you believe that you would have to write a dump and load call for every structure and datatype for an INI file.  It’s only a significant amount of work because you’re almost certainly going about solving the problem the wrong way.&lt;/blockquote&gt;

I didn&#039;t word that very clearly, but I meant that rolling my own dump and load for INI instead of using the already existing ones for YAML would have been more lines of code because I have used various random data types including dictionaries inside lists, all sorts of different types of literals that need to be parsed correctly, etc.  Look at the code for YAML&#039;s dump and load routines if you want proof of it doing things that you can&#039;t do in 20 lines of code.  My point is that dump/load for arbitrary Python structures is a feature that I am using and someone has already written code to do it so I might as well use it rather than trying to re-invent the wheel.

&lt;blockquote cite=&quot;#comment-content-31701&quot;&gt;Plus, a YAML configuration file is not a magic bullet.  Sure, you get automatic type marshaling, but you lack automatic merging of files (at least 10 lines you have to write, easily more depending on your needs), built-in defaults, and case-insensitive parsing (list is not exhaustive).  &lt;/blockquote&gt;

Right nothing&#039;s a magic bullet, and since I&#039;m using a general purpose YAML library for config files it doesn&#039;t have any config file specific stuff in it. There&#039;s always trade-offs.  If I was doing more complicated types of things for config files that needed finer grained control I might look into ConfigParser and whatnot but generally I just need to dump my internal settings data into a file that I can edit so YAML works for that.

&lt;blockquote cite=&quot;#comment-content-31701&quot;&gt;My real theory, though, is that whatever you’re serializing probably really isn’t configuration data or isn’t just configuration data.&lt;/blockquote&gt;

I&#039;ve used YAML for all sorts of things in Python, the same way that I used XML for all sorts of things in C# and whatnot, but the serialization aspect makes for a lot less boilerplate code in most cases in general.  If I can avoid writing parsing and serialization code in a lot of places where I would otherwise have to write it I might as well save myself the time.  YAML&#039;s a tool that&#039;s there for me to use and one of the things I use it for is config files because it works pretty well for that for a lot of different structures and types of config files.  If someday I run into a config file situation where YAML doesn&#039;t work well then I&#039;ll use something else or write some code to make YAML do it, whichever makes more sense to do, but for now it does what I need it to do and doesn&#039;t get in my way.]]></description>
			<content:encoded><![CDATA[<blockquote cite="#comment-content-31701"><p>
<strong><a href="#comment-31701" rel="nofollow">Adam Skutt</a> :</strong><br />
    I’m not sure why you believe that you would have to write a dump and load call for every structure and datatype for an INI file.  It’s only a significant amount of work because you’re almost certainly going about solving the problem the wrong way.</p></blockquote>
<p>I didn&#8217;t word that very clearly, but I meant that rolling my own dump and load for INI instead of using the already existing ones for YAML would have been more lines of code because I have used various random data types including dictionaries inside lists, all sorts of different types of literals that need to be parsed correctly, etc.  Look at the code for YAML&#8217;s dump and load routines if you want proof of it doing things that you can&#8217;t do in 20 lines of code.  My point is that dump/load for arbitrary Python structures is a feature that I am using and someone has already written code to do it so I might as well use it rather than trying to re-invent the wheel.</p>
<blockquote cite="#comment-content-31701"><p>Plus, a YAML configuration file is not a magic bullet.  Sure, you get automatic type marshaling, but you lack automatic merging of files (at least 10 lines you have to write, easily more depending on your needs), built-in defaults, and case-insensitive parsing (list is not exhaustive).  </p></blockquote>
<p>Right nothing&#8217;s a magic bullet, and since I&#8217;m using a general purpose YAML library for config files it doesn&#8217;t have any config file specific stuff in it. There&#8217;s always trade-offs.  If I was doing more complicated types of things for config files that needed finer grained control I might look into ConfigParser and whatnot but generally I just need to dump my internal settings data into a file that I can edit so YAML works for that.</p>
<blockquote cite="#comment-content-31701"><p>My real theory, though, is that whatever you’re serializing probably really isn’t configuration data or isn’t just configuration data.</p></blockquote>
<p>I&#8217;ve used YAML for all sorts of things in Python, the same way that I used XML for all sorts of things in C# and whatnot, but the serialization aspect makes for a lot less boilerplate code in most cases in general.  If I can avoid writing parsing and serialization code in a lot of places where I would otherwise have to write it I might as well save myself the time.  YAML&#8217;s a tool that&#8217;s there for me to use and one of the things I use it for is config files because it works pretty well for that for a lot of different structures and types of config files.  If someday I run into a config file situation where YAML doesn&#8217;t work well then I&#8217;ll use something else or write some code to make YAML do it, whichever makes more sense to do, but for now it does what I need it to do and doesn&#8217;t get in my way.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Adam Skutt		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31812</link>

		<dc:creator><![CDATA[Adam Skutt]]></dc:creator>
		<pubDate>Thu, 28 Jun 2012 11:17:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31812</guid>

					<description><![CDATA[The problem is more the fact you have no idea what you will end up adding to your search path.  That&#039;s bad. Loading an absolute path is problematic enough that I can&#039;t recommend it (i.e., all the examples you get from a quick googling are utterly wrong) and it isn&#039;t technically portable anyway.

As for trust, the &quot;should&quot; is the entire problem with that statement.  Lots of websites out there about what happens when one &quot;should&quot; be able to trust something and actually cannot...

Even if I bought solutions to those issues, you&#039;re still left with a file that&#039;s a pain to manipuate externally, especially graphically.  Regenerating python source is a PITA unless the source is very trivial.  In which case, just about everything else (including an INI) file will be less code for everyone.  They&#039;re just simply an inferior solution.  The only times they have any merit is for library &quot;configuration&quot; files which are never seen and edited by end-users/admins, but only developers.]]></description>
			<content:encoded><![CDATA[<p>The problem is more the fact you have no idea what you will end up adding to your search path.  That&#8217;s bad. Loading an absolute path is problematic enough that I can&#8217;t recommend it (i.e., all the examples you get from a quick googling are utterly wrong) and it isn&#8217;t technically portable anyway.</p>
<p>As for trust, the &#8220;should&#8221; is the entire problem with that statement.  Lots of websites out there about what happens when one &#8220;should&#8221; be able to trust something and actually cannot&#8230;</p>
<p>Even if I bought solutions to those issues, you&#8217;re still left with a file that&#8217;s a pain to manipuate externally, especially graphically.  Regenerating python source is a PITA unless the source is very trivial.  In which case, just about everything else (including an INI) file will be less code for everyone.  They&#8217;re just simply an inferior solution.  The only times they have any merit is for library &#8220;configuration&#8221; files which are never seen and edited by end-users/admins, but only developers.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: berdario		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31797</link>

		<dc:creator><![CDATA[berdario]]></dc:creator>
		<pubDate>Thu, 28 Jun 2012 09:46:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31797</guid>

					<description><![CDATA[Adam Skutt:

I&#039;ll pick only this among the many things I don&#039;t agree you with (the other are less interesting/important or have been already dealt with by others):

you say that is bad to have .py files inside /etc, I assume this is due to security reasons:

1- almost all the files inside /etc are sensible
even if they&#039;re not executable, changing something inside of them may expose sensitive data or be a security breach in some other way... just think about ssh, fstab, sudoers

2- for this reason, all the files have write permissions only for the root user

I agree that with a non-executable file you may have a smaller attack-surface, and I don&#039;t think that it&#039;s wise to use .py files everywhere willy-nilly

but in the end: I find that you should be able to trust your (read only) configuration files as much as you trust your executable code]]></description>
			<content:encoded><![CDATA[<p>Adam Skutt:</p>
<p>I&#8217;ll pick only this among the many things I don&#8217;t agree you with (the other are less interesting/important or have been already dealt with by others):</p>
<p>you say that is bad to have .py files inside /etc, I assume this is due to security reasons:</p>
<p>1- almost all the files inside /etc are sensible<br />
even if they&#8217;re not executable, changing something inside of them may expose sensitive data or be a security breach in some other way&#8230; just think about ssh, fstab, sudoers</p>
<p>2- for this reason, all the files have write permissions only for the root user</p>
<p>I agree that with a non-executable file you may have a smaller attack-surface, and I don&#8217;t think that it&#8217;s wise to use .py files everywhere willy-nilly</p>
<p>but in the end: I find that you should be able to trust your (read only) configuration files as much as you trust your executable code</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Adam Skutt		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31701</link>

		<dc:creator><![CDATA[Adam Skutt]]></dc:creator>
		<pubDate>Thu, 28 Jun 2012 01:53:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31701</guid>

					<description><![CDATA[I&#039;m not sure why you believe that you would have to write a dump and load call for every structure and datatype for an INI file.  It&#039;s only a significant amount of work because you&#039;re almost certainly going about solving the problem the wrong way.

Plus, a YAML configuration file is not a magic bullet.  Sure, you get automatic type marshaling, but you lack automatic merging of files (at least 10 lines you have to write, easily more depending on your needs), built-in defaults, and case-insensitive parsing (list is not exhaustive).  

My real theory, though, is that whatever you&#039;re serializing probably really isn&#039;t configuration data or isn&#039;t just configuration data.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not sure why you believe that you would have to write a dump and load call for every structure and datatype for an INI file.  It&#8217;s only a significant amount of work because you&#8217;re almost certainly going about solving the problem the wrong way.</p>
<p>Plus, a YAML configuration file is not a magic bullet.  Sure, you get automatic type marshaling, but you lack automatic merging of files (at least 10 lines you have to write, easily more depending on your needs), built-in defaults, and case-insensitive parsing (list is not exhaustive).  </p>
<p>My real theory, though, is that whatever you&#8217;re serializing probably really isn&#8217;t configuration data or isn&#8217;t just configuration data.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Chris Graham		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31550</link>

		<dc:creator><![CDATA[Chris Graham]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 18:18:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31550</guid>

					<description><![CDATA[&lt;blockquote cite=&quot;#comment-content-31479&quot;&gt;
&lt;strong&gt;&lt;a href=&quot;#comment-31479&quot; rel=&quot;nofollow&quot;&gt;Adam Skutt&lt;/a&gt; :&lt;/strong&gt;
    Dealing with the “shortcomings”, in this case, seems to you take about 20 lines, and even generalized, I think it wouldn’t be too much more.  Writing a load/dump pair to take an INI file and convert to/from hierarchical dictionaries is easy.&lt;/blockquote&gt;

Personally I just use YAML and writing the equivalent to the simple .dump and .load calls for every possible structure and set of data types I&#039;ve used would have been a significant amount of work.  Serialization is not an inherently easy feature to implement.  I like YAML because with the Python library I get serialization built-in, plus it&#039;s decently human readable/editable, and if I ever have to import them from an app that isn&#039;t written in Python it&#039;s in a standard format that probably won&#039;t result in a lot more work writing a new parser.  Like with anything else I am going to go with the solution that takes two lines of code over the solution that takes 20 lines of code if the 20 line version doesn&#039;t have any significant benefits.]]></description>
			<content:encoded><![CDATA[<blockquote cite="#comment-content-31479"><p>
<strong><a href="#comment-31479" rel="nofollow">Adam Skutt</a> :</strong><br />
    Dealing with the “shortcomings”, in this case, seems to you take about 20 lines, and even generalized, I think it wouldn’t be too much more.  Writing a load/dump pair to take an INI file and convert to/from hierarchical dictionaries is easy.</p></blockquote>
<p>Personally I just use YAML and writing the equivalent to the simple .dump and .load calls for every possible structure and set of data types I&#8217;ve used would have been a significant amount of work.  Serialization is not an inherently easy feature to implement.  I like YAML because with the Python library I get serialization built-in, plus it&#8217;s decently human readable/editable, and if I ever have to import them from an app that isn&#8217;t written in Python it&#8217;s in a standard format that probably won&#8217;t result in a lot more work writing a new parser.  Like with anything else I am going to go with the solution that takes two lines of code over the solution that takes 20 lines of code if the 20 line version doesn&#8217;t have any significant benefits.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Adam Skutt		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31479</link>

		<dc:creator><![CDATA[Adam Skutt]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 15:34:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31479</guid>

					<description><![CDATA[Dealing with the &quot;shortcomings&quot;, in this case, seems to you take about 20 lines, and even generalized, I think it wouldn&#039;t be too much more.  Writing a load/dump pair to take an INI file and convert to/from hierarchical dictionaries is easy.

The biggest &quot;shortcoming&quot; over JSON and a few other libraries is that ConfigParser will not perform automatic type conversion, but there are other libraries out there that will do that if you absolutely must have it.  I&#039;m not entirely sold on that as a must-have feature, but it&#039;s hardly difficult to achieve.  

Of course, the other libraries have their own shortcomings: ConfigParser has built-in support for loading configuration from  multiple files, something I would have to write for the other libraries.]]></description>
			<content:encoded><![CDATA[<p>Dealing with the &#8220;shortcomings&#8221;, in this case, seems to you take about 20 lines, and even generalized, I think it wouldn&#8217;t be too much more.  Writing a load/dump pair to take an INI file and convert to/from hierarchical dictionaries is easy.</p>
<p>The biggest &#8220;shortcoming&#8221; over JSON and a few other libraries is that ConfigParser will not perform automatic type conversion, but there are other libraries out there that will do that if you absolutely must have it.  I&#8217;m not entirely sold on that as a must-have feature, but it&#8217;s hardly difficult to achieve.  </p>
<p>Of course, the other libraries have their own shortcomings: ConfigParser has built-in support for loading configuration from  multiple files, something I would have to write for the other libraries.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Stefano Costa		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31431</link>

		<dc:creator><![CDATA[Stefano Costa]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 13:22:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31431</guid>

					<description><![CDATA[Adam, it is possible to serialize dictionaries into INI files. But I don&#039;t think there is an equivalent of json.dumps() or json.loads(). Am I wrong? This introduces another layer - like I did here https://bitbucket.org/steko/totalopenstation/src/af7248e3e4f0/totalopenstation/utils/upref.py and I intend to get rid of it soon. Of course my code might not be perfect, but it tries to deal with the shortcomings of ConfigParser.]]></description>
			<content:encoded><![CDATA[<p>Adam, it is possible to serialize dictionaries into INI files. But I don&#8217;t think there is an equivalent of json.dumps() or json.loads(). Am I wrong? This introduces another layer &#8211; like I did here <a href="https://bitbucket.org/steko/totalopenstation/src/af7248e3e4f0/totalopenstation/utils/upref.py" rel="nofollow ugc">https://bitbucket.org/steko/totalopenstation/src/af7248e3e4f0/totalopenstation/utils/upref.py</a> and I intend to get rid of it soon. Of course my code might not be perfect, but it tries to deal with the shortcomings of ConfigParser.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Adam Skutt		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31380</link>

		<dc:creator><![CDATA[Adam Skutt]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 11:03:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31380</guid>

					<description><![CDATA[berdario,

Saying &#039;serialization!=binary&#039; means you&#039;re in tacit agreement with me anyway. It&#039;s perfectly possible to serialize dictionaries into INI files.  My point was hopefully obvious: how and where you store your configuration matters a lot: you can&#039;t just shove serialized data wherever,  you want in whatever format you please.  I did say &#039;text file&#039; in my post for a reason, after all.  (Aside: YAML is a hot mess.)  

Putting a .py file in /etc or $HOME is an obviously bad idea, which is why you don&#039;t replace read-only configuration with a Python source file.  Expecting an admin to go to /usr/lib/python2.6/site-packages/myapp/config.py just to edit  the DB host because it was moved doesn&#039;t do anything but make me a jerk.  Especially when it doesn&#039;t save me any code!  So yes, putting it in a .py file is hardcoding and effectively making it &quot;constant forever&quot;.

Django&#039;s settings.py isn&#039;t meant for end-users, so it&#039;s not the least bit relevant here.

Kay,

Reading a file and feeding it to exec is an awesome way to get hacked if the program does anything privileged.  There are packages out there that allow you to have python expressions be safely limited and evaluated.  The original was &#039;unrepr&#039; which was integrated into various other things.  
Code and data aren&#039;t loaded the same way, so replacing a config file with an INI file is hardcoding the values, like it or not.]]></description>
			<content:encoded><![CDATA[<p>berdario,</p>
<p>Saying &#8216;serialization!=binary&#8217; means you&#8217;re in tacit agreement with me anyway. It&#8217;s perfectly possible to serialize dictionaries into INI files.  My point was hopefully obvious: how and where you store your configuration matters a lot: you can&#8217;t just shove serialized data wherever,  you want in whatever format you please.  I did say &#8216;text file&#8217; in my post for a reason, after all.  (Aside: YAML is a hot mess.)  </p>
<p>Putting a .py file in /etc or $HOME is an obviously bad idea, which is why you don&#8217;t replace read-only configuration with a Python source file.  Expecting an admin to go to /usr/lib/python2.6/site-packages/myapp/config.py just to edit  the DB host because it was moved doesn&#8217;t do anything but make me a jerk.  Especially when it doesn&#8217;t save me any code!  So yes, putting it in a .py file is hardcoding and effectively making it &#8220;constant forever&#8221;.</p>
<p>Django&#8217;s settings.py isn&#8217;t meant for end-users, so it&#8217;s not the least bit relevant here.</p>
<p>Kay,</p>
<p>Reading a file and feeding it to exec is an awesome way to get hacked if the program does anything privileged.  There are packages out there that allow you to have python expressions be safely limited and evaluated.  The original was &#8216;unrepr&#8217; which was integrated into various other things.<br />
Code and data aren&#8217;t loaded the same way, so replacing a config file with an INI file is hardcoding the values, like it or not.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Zap		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31374</link>

		<dc:creator><![CDATA[Zap]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 10:54:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31374</guid>

					<description><![CDATA[I&#039;ve tried .py configuration files as a replacement for .ini files in the past. Without success. 

First of all I ran into the problem that I used __import__ to load the users Python script. The scripts path was passed via command line. I had a support case where the imported script didn&#039;t seem to contain the expected settings. Reason was an old .pyc file with an identical name lying next to my start script. 

That was the reason, that I switched to the &quot;evil&quot; exec. 
But some time later I had other support request with a user complaining that a settings like temp_file = &quot;C:\temp\log.txt&quot; doesn&#039;t work! Why!? - Backslash needs to be quoted (or use raw-string syntax).

There have been other issues like missing # coding:  declarations if Non-ASCII characters are used.

Finally I discontinued the use of .py files as configuration file and didn&#039;t have any trouble with this approach.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve tried .py configuration files as a replacement for .ini files in the past. Without success. </p>
<p>First of all I ran into the problem that I used __import__ to load the users Python script. The scripts path was passed via command line. I had a support case where the imported script didn&#8217;t seem to contain the expected settings. Reason was an old .pyc file with an identical name lying next to my start script. </p>
<p>That was the reason, that I switched to the &#8220;evil&#8221; exec.<br />
But some time later I had other support request with a user complaining that a settings like temp_file = &#8220;C:\temp\log.txt&#8221; doesn&#8217;t work! Why!? &#8211; Backslash needs to be quoted (or use raw-string syntax).</p>
<p>There have been other issues like missing # coding:  declarations if Non-ASCII characters are used.</p>
<p>Finally I discontinued the use of .py files as configuration file and didn&#8217;t have any trouble with this approach.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Thomas Kluyver		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31367</link>

		<dc:creator><![CDATA[Thomas Kluyver]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 10:32:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31367</guid>

					<description><![CDATA[For IPython, we switched to using Python files for configuration, but I think this was a bit hasty. So long as the user is happy to edit a text file to change settings, Python code is fine. But if you want any way to change settings inside the application (like a preferences dialog), there&#039;s no good way to automatically write a correct Python file. With INI files, the application can easily write out a modified form.

Of course, other formats like JSON can do that as well. But INI files are very easy to work with manually.]]></description>
			<content:encoded><![CDATA[<p>For IPython, we switched to using Python files for configuration, but I think this was a bit hasty. So long as the user is happy to edit a text file to change settings, Python code is fine. But if you want any way to change settings inside the application (like a preferences dialog), there&#8217;s no good way to automatically write a correct Python file. With INI files, the application can easily write out a modified form.</p>
<p>Of course, other formats like JSON can do that as well. But INI files are very easy to work with manually.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Kay Hayen		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31347</link>

		<dc:creator><![CDATA[Kay Hayen]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 08:51:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31347</guid>

					<description><![CDATA[I have done both. I have used configuration files that contain

var_name = value

and used &quot;exec&quot; to read it. It&#039;s dead simple, quick to introduce,
and allows you to do things e.g. dependent on user name, host name
with no effort, but people may not ever notice that it&#039;s Python code at all. Same works for shell code too.

I have also used configuration files that are &quot;ini&quot; files or XML, and I believe that XML sucks for configuration, but ini files have a nice Python module that handles them.

I found that XMl and &quot;ini&quot; are better for structured configuration. If e.g. the ini sections can reference another in values, that&#039;s nice, or the XML you can easily find lists, etc. with lxml and xpath queries, so it&#039;s easier to consume.

One thing that code is typically very bad at, is to check if the configuration values actually have any effect. For that, you would have to check the values it produces, so that typos do not go unnoticed. But e.g. a duplicate definition later in the file, you typically cannot warn about it.

I believe configuration files have their place. But really the best is to avoid configuration entirely. For my compiler, I e.g. only have command line arguments. Put a call to it in a script, that is the configuration file format, that I consider sufficient.

Yours,
Kay]]></description>
			<content:encoded><![CDATA[<p>I have done both. I have used configuration files that contain</p>
<p>var_name = value</p>
<p>and used &#8220;exec&#8221; to read it. It&#8217;s dead simple, quick to introduce,<br />
and allows you to do things e.g. dependent on user name, host name<br />
with no effort, but people may not ever notice that it&#8217;s Python code at all. Same works for shell code too.</p>
<p>I have also used configuration files that are &#8220;ini&#8221; files or XML, and I believe that XML sucks for configuration, but ini files have a nice Python module that handles them.</p>
<p>I found that XMl and &#8220;ini&#8221; are better for structured configuration. If e.g. the ini sections can reference another in values, that&#8217;s nice, or the XML you can easily find lists, etc. with lxml and xpath queries, so it&#8217;s easier to consume.</p>
<p>One thing that code is typically very bad at, is to check if the configuration values actually have any effect. For that, you would have to check the values it produces, so that typos do not go unnoticed. But e.g. a duplicate definition later in the file, you typically cannot warn about it.</p>
<p>I believe configuration files have their place. But really the best is to avoid configuration entirely. For my compiler, I e.g. only have command line arguments. Put a call to it in a script, that is the configuration file format, that I consider sufficient.</p>
<p>Yours,<br />
Kay</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Beetroot Dog		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31284</link>

		<dc:creator><![CDATA[Beetroot Dog]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 03:31:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31284</guid>

					<description><![CDATA[Did you guys read the article?

It doesn&#039;t say to &quot;hardcode&quot; values throughout a program rather than use config files - rather, that config files should be .py files.

The main reason to use .ini etc. files is to enable non-developers to change the values. So if that is not required then yeah why not just use python files with simple dicts etc.]]></description>
			<content:encoded><![CDATA[<p>Did you guys read the article?</p>
<p>It doesn&#8217;t say to &#8220;hardcode&#8221; values throughout a program rather than use config files &#8211; rather, that config files should be .py files.</p>
<p>The main reason to use .ini etc. files is to enable non-developers to change the values. So if that is not required then yeah why not just use python files with simple dicts etc.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: berdario		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31280</link>

		<dc:creator><![CDATA[berdario]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 03:02:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31280</guid>

					<description><![CDATA[I think that Adam Skutt misses the point:

1- serialization != binary
yaml (a text file) is as user friendly as any other ini file, and much more so than an xml
I fail to understand how this might (not) work with Windows&#039; Group Policy... In theory it should be exactly the same, but obviously every tools has its limitations (if you have such constraints you can design your application around it, but this doesn&#039;t detracts from Rob&#039;s idea)

2- shipping a default config.py and importing from it isn&#039;t hardcoding it at all imho... even if you&#039;re obfuscating your python code, you can just keep the config.py in the clear to let the user modify it
I never heard anyone say something along the lines of: &quot;I wish Django had an INI instead of its settings.py&quot;]]></description>
			<content:encoded><![CDATA[<p>I think that Adam Skutt misses the point:</p>
<p>1- serialization != binary<br />
yaml (a text file) is as user friendly as any other ini file, and much more so than an xml<br />
I fail to understand how this might (not) work with Windows&#8217; Group Policy&#8230; In theory it should be exactly the same, but obviously every tools has its limitations (if you have such constraints you can design your application around it, but this doesn&#8217;t detracts from Rob&#8217;s idea)</p>
<p>2- shipping a default config.py and importing from it isn&#8217;t hardcoding it at all imho&#8230; even if you&#8217;re obfuscating your python code, you can just keep the config.py in the clear to let the user modify it<br />
I never heard anyone say something along the lines of: &#8220;I wish Django had an INI instead of its settings.py&#8221;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: robert		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31272</link>

		<dc:creator><![CDATA[robert]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 02:26:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31272</guid>

					<description><![CDATA[I pretty much wanted to write what Adam said. The other reason is: ini/cfg files are simple!

Key = value is just so simple, there&#039;s very little danger of messing it up if you manually edit it, unlike XML or JSON (oh no, a bracket is missing! ;) ).

I can just tell other people, even extremely un-technical artists, &quot;hey open that file and edit value so-and-so&quot;. It allows for easy troubleshooting and config changing.

Also since we use Qt a lot we can use QSettings, which works with ini files (or the registry). It&#039;s a pretty neat system - set a flag and it uses the registry, or the user folder, or the program&#039;s own folder. Works on OS X, Linux and Windows. Works the same on C++ and Python. I really like it.

There&#039;s probably better and more sophisticated and elegant ways, I agree, but often simple is best.]]></description>
			<content:encoded><![CDATA[<p>I pretty much wanted to write what Adam said. The other reason is: ini/cfg files are simple!</p>
<p>Key = value is just so simple, there&#8217;s very little danger of messing it up if you manually edit it, unlike XML or JSON (oh no, a bracket is missing! ;) ).</p>
<p>I can just tell other people, even extremely un-technical artists, &#8220;hey open that file and edit value so-and-so&#8221;. It allows for easy troubleshooting and config changing.</p>
<p>Also since we use Qt a lot we can use QSettings, which works with ini files (or the registry). It&#8217;s a pretty neat system &#8211; set a flag and it uses the registry, or the user folder, or the program&#8217;s own folder. Works on OS X, Linux and Windows. Works the same on C++ and Python. I really like it.</p>
<p>There&#8217;s probably better and more sophisticated and elegant ways, I agree, but often simple is best.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Adam Skutt		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31259</link>

		<dc:creator><![CDATA[Adam Skutt]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 01:36:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31259</guid>

					<description><![CDATA[The answer to first is simple: other people may want to modify configuration outside your application. There are tons of legitimate reasons to do this, and this ability (Group Policy) is one of the reasons Windows is so far ahead in enterprise desktop administration.  Failing GP, text files are vastly easier to edit and manage than binary blobs.

The answer to the second is equally simple: just because something is read-only doesn&#039;t make it constant forever.  The application I wrote today doesn&#039;t edit the database connection data supplied in its INI file, but the two alternatives: a) make the user supply it every time, or b) hard code it, are both plainly silly. 

I think you also vastly overestimate the difficulty in using ini or xml configuration files in Python.  It&#039;s very simple, even if your needs are complicated.  Lots of people have written useful and easy to use libraries if the built-in ones do not meet your needs.]]></description>
			<content:encoded><![CDATA[<p>The answer to first is simple: other people may want to modify configuration outside your application. There are tons of legitimate reasons to do this, and this ability (Group Policy) is one of the reasons Windows is so far ahead in enterprise desktop administration.  Failing GP, text files are vastly easier to edit and manage than binary blobs.</p>
<p>The answer to the second is equally simple: just because something is read-only doesn&#8217;t make it constant forever.  The application I wrote today doesn&#8217;t edit the database connection data supplied in its INI file, but the two alternatives: a) make the user supply it every time, or b) hard code it, are both plainly silly. </p>
<p>I think you also vastly overestimate the difficulty in using ini or xml configuration files in Python.  It&#8217;s very simple, even if your needs are complicated.  Lots of people have written useful and easy to use libraries if the built-in ones do not meet your needs.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Andrew Robert		</title>
		<link>https://www.robg3d.com/2012/06/why-bother-with-python-and-config-files/#comment-31257</link>

		<dc:creator><![CDATA[Andrew Robert]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 01:32:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.robg3d.com/?p=1000#comment-31257</guid>

					<description><![CDATA[I can think of one very compeling reason to use config files. Change Control. In an enterprise environment, it is far easier to modify config files than endure a potentially gruelling change control and code review process when all you want to do is change data or existing program behavior. Even a very minor change can cause a tidal wave of paperwork best avoided if possible. Its far better to design an app with the maximum amount of flexibility possible so future code changes are minor and infrequent.]]></description>
			<content:encoded><![CDATA[<p>I can think of one very compeling reason to use config files. Change Control. In an enterprise environment, it is far easier to modify config files than endure a potentially gruelling change control and code review process when all you want to do is change data or existing program behavior. Even a very minor change can cause a tidal wave of paperwork best avoided if possible. Its far better to design an app with the maximum amount of flexibility possible so future code changes are minor and infrequent.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
