<br><br><div class="gmail_quote">On 10 February 2012 15:36, Raymond Wagner <span dir="ltr">&lt;<a href="mailto:raymond@wagnerrp.com">raymond@wagnerrp.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 2/10/2012 09:12, David Crawford wrote:<br>
&gt; path = &#39;%cn %cc %cN.srt&#39;<br>
<br>
</div>Doing this in Python means you&#39;ve stored that string to the variable<br>
&#39;path&#39;.  Now in Python, everything is object, and objects have methods.<br>
In this particular case, you want to use the &#39;replace&#39; method, which<br>
replaces one string with another, and outputs the result.  That is this...<br>
<div class="im"><br>
&gt;     path = path.replace(&#39;%&#39;+tag, tmp)<br>
<br>
</div>In Python, strings are &#39;mutable&#39;, meaning they cannot be changed.  The<br>
only way to modify the string stored to a variable is to store a new<br>
string to that variable, as described above.  Except you don&#39;t want that<br>
path string up there.  You want to use this one defined lower...<br>
<br>
&gt; &#39;%m-%d_%H-%i-%s_%cN_%T&#39;<br>
<br>
So define that to a variable, and replace whatever the bindings can&#39;t<br>
handle.  That&#39;s what this does down here.<br>
<div class="im"><br>
&gt; for (tag, data) in ((&#39;cn&#39;, &#39;channum&#39;),(&#39;cc&#39;,&#39;callsign&#39;),(&#39;cN&#39;,&#39;name&#39;)):<br>
&gt;     tmp = unicode(chan[data]).replace(&#39;/&#39;,&#39;-&#39;)<br>
&gt;     path = path.replace(&#39;%&#39;+tag, tmp)<br>
<br>
</div>It loops through those three sets of values, setting &#39;tag&#39; to &#39;cn&#39;, and<br>
&#39;data&#39; to &#39;channum&#39; on the first pass.  The Channel class is configured<br>
to imitate a dictionary, or map, or associative array, depending on your<br>
programming language of preference.  When it pulls &#39;chan[data]&#39;, it is<br>
pulling the value mapped to the string currently stored in the &#39;data&#39;<br>
variable, which is &#39;channum&#39;, out of that associative array.<br>
<br>
Now you&#39;re only trying to use %cN, so there is no need for this<br>
construct.  You can just do the following directly...<br>
<br>
&gt; path = &#39;%m-%d_%H-%i-%s_%cN_%T&#39;<br>
&gt; chan = Channel(chanid)<br>
&gt; path = path.replace(&#39;%cN&#39;, <a href="http://chan.name" target="_blank">chan.name</a>)<br>
<br>
The Channel class makes all of those associative array values also<br>
available as class attributes.  Attributes are just variables stored<br>
against an object, and accessed in the same manner as methods (with a<br>
&#39;.&#39;).  Remember, you still need to feed this new, modified path into the<br>
&#39;formatPath&#39; method, to get out your desired result.<br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
mythtv-users mailing list<br>
<a href="mailto:mythtv-users@mythtv.org">mythtv-users@mythtv.org</a><br>
<a href="http://www.mythtv.org/mailman/listinfo/mythtv-users" target="_blank">http://www.mythtv.org/mailman/listinfo/mythtv-users</a><br>
</div></div></blockquote></div><br>