Hello Leszek,

How about:


>>> var = "fo a"
>>> var[2]
' '
>>> var[2] == ' '
True


JM

> Le 10 déc. 2015 à 11:33, Leszek Wroński <[email protected]> a écrit :
> 
> Guys,
> 
> Frescobaldi has the useful 'slur for the selected notes' snippet under C-(. I 
> want to have the same functionality for beams. That is, I want to be able to 
> select some notes, and then via the snippet insert a '[' in the first space 
> (that is, after the first note), and then a ']' at the end.
> 
> Unfortunately, I have never in my life written a line of python... till this 
> day, that is. So, I'm trying the following ('W' is for whitespace):
> 
> 1 -*- name: mybeam; python; selection: strip;
> 2 x = 0
> 3 mysequence = text
> 4 while x < len(text):
> 5 WW if text[x] == ' ':
> 6 WWWW mysequence[x] = '['
> 7 WWWW break
> 8 WW x = x + 1
> 9 text = mysequence + ']'  
> 
> Notice that line 5 contains a space between the quotes. Of course I need to 
> add conditions regarding what to do if there's no space in the selection etc. 
> But that's for later, once this basic script actually works. As you can see, 
> I thought I'd copy the selection to 'mysequence' string to manipulate on it; 
> this is probably unneeded. But after writing the above I got, at line 5, an 
> error "TypeError: 'unicode' object does not support item assignment".
> 
> What I found weird is that to my untrained eyes line 5 does no assigning, but 
> rather checks whether the xth element of the string text is a space. Anyway, 
> after some googling I decided to substitute "is" for "==" in line 5. Right 
> now the script does not give any errors, but it only adds a ']' at the end of 
> the selection. I'm apparently unable to check whether the xth element of the 
> string text is a space. I tried
> 
> if text[x] == ' %d':
> 
> and
> 
> if text[x] ==  u"\u0020":
> 
> and
> 
> if text[x].isspace():
> 
> to no avail (the last one gave the "unicode object does not support item 
> assignment" error again, which I don't understand at all, having copied the 
> command from 
> http://www.ehow.com/how_12112665_determine-character-whitespace-python.html 
> <http://www.ehow.com/how_12112665_determine-character-whitespace-python.html>).
>  Could anyone give me a hint on this?
> 
> Best regards,
> 
> Leszek.
> 
> _______________________________________________
> lilypond-user mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/lilypond-user

_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to