<div dir="ltr">Some quick thoughts:<div><br></div><div>If the data is only written and used by your own program, it doesn't make much of a difference whether you use Python (as Django does) or YAML. Obviously if it has to be used in another language or by other tools, Python is probably not a good option.</div><div><br></div><div>You can output Python (deserialize objects) using the pickle module (<a href="https://docs.python.org/2/library/pickle.html">https://docs.python.org/2/library/pickle.html</a>), but it can execute arbitrary code, so do not use it from untrusted sources, which is also very explicitly stated in the official python docs.</div><div><br></div><div>If the data might possibly be from an outside source, I would go with JSON. YAML is prettier and also a superset of JSON, but some of the more advanced features of YAML are exploitable. Ruby on Rails had a string of vulnerabilities last year based off YAML deserialization. (<a href="https://ronin-ruby.github.io/blog/2013/01/09/rails-pocs.html">https://ronin-ruby.github.io/blog/2013/01/09/rails-pocs.html</a>, <a href="https://ronin-ruby.github.io/blog/2013/01/28/new-rails-poc.html">https://ronin-ruby.github.io/blog/2013/01/28/new-rails-poc.html</a>). Again, if the source is trusted, then it shouldn't be too big of an issue.</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">Cheers,<br>XY</div></div>
<br><div class="gmail_quote">On Thu, Nov 13, 2014 at 9:19 AM,  <span dir="ltr"><<a href="mailto:jep200404@columbus.rr.com" target="_blank">jep200404@columbus.rr.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I saw some complex data for initial values in an ugly format.<br>
Someone else saw it and immediately said to use YAML.<br>
<br>
I realized that if the configuration data is used only in a<br>
Python program, then the configuration data could be a Python<br>
module, and just be imported. So now I'm wondering about YAML<br>
versus Python. When is YAML more helpful than Python and vice<br>
versa?<br>
<br>
If one needs to use the data in any language other<br>
than Python, then Python would be inappropriate, because one<br>
would need a Python parser for some other language, which<br>
would be rediculous. YAML can be grokked by many languages.<br>
<br>
If one needs modify the data by a program,<br>
then YAML is superior because it's easy to output.<br>
Importing Python is easy, but I'm not aware of a way to easily<br>
output Python. print(repr(foo)) could be a part of it,<br>
but it tends towards long lines which are hard to read.<br>
<br>
The references in YAML are interesting.<br>
It makes me wonder about recursive references in Python.<br>
I had not though about recursive data structures in Python.<br>
(I have not needed them yet either.)<br>
<br>
Also, as clean as Python is, it has more syntax cruft to wade<br>
through than YAML. YAML is easier to read.<br>
<br>
Golly, I think I've talked myself into YAML.<br>
What can you add about YAML versus Python for static or<br>
initializing data?<br>
_______________________________________________<br>
CentralOH mailing list<br>
<a href="mailto:CentralOH@python.org">CentralOH@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/centraloh" target="_blank">https://mail.python.org/mailman/listinfo/centraloh</a><br>
</blockquote></div><br></div></div>