<br><br><div class="gmail_quote">On 10 February 2012 15:36, Raymond Wagner <span dir="ltr"><<a href="mailto:raymond@wagnerrp.com">raymond@wagnerrp.com</a>></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>
> path = '%cn %cc %cN.srt'<br>
<br>
</div>Doing this in Python means you've stored that string to the variable<br>
'path'. Now in Python, everything is object, and objects have methods.<br>
In this particular case, you want to use the 'replace' method, which<br>
replaces one string with another, and outputs the result. That is this...<br>
<div class="im"><br>
> path = path.replace('%'+tag, tmp)<br>
<br>
</div>In Python, strings are 'mutable', 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't want that<br>
path string up there. You want to use this one defined lower...<br>
<br>
> '%m-%d_%H-%i-%s_%cN_%T'<br>
<br>
So define that to a variable, and replace whatever the bindings can't<br>
handle. That's what this does down here.<br>
<div class="im"><br>
> for (tag, data) in (('cn', 'channum'),('cc','callsign'),('cN','name')):<br>
> tmp = unicode(chan[data]).replace('/','-')<br>
> path = path.replace('%'+tag, tmp)<br>
<br>
</div>It loops through those three sets of values, setting 'tag' to 'cn', and<br>
'data' to 'channum' 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 'chan[data]', it is<br>
pulling the value mapped to the string currently stored in the 'data'<br>
variable, which is 'channum', out of that associative array.<br>
<br>
Now you're only trying to use %cN, so there is no need for this<br>
construct. You can just do the following directly...<br>
<br>
> path = '%m-%d_%H-%i-%s_%cN_%T'<br>
> chan = Channel(chanid)<br>
> path = path.replace('%cN', <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>
'.'). Remember, you still need to feed this new, modified path into the<br>
'formatPath' 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>