string weirdness in pyruni
Date | 2016-11-07 13:45 |
From | Richard |
Subject | string weirdness in pyruni |
Some perfectly legal Python code generates a syntax error in pyruni: pyruni: python exception File " |
Date | 2016-11-07 14:21 |
From | Francois PINOT |
Subject | Re: string weirdness in pyruni |
This is a tricky issue. The python code passed to pyruni is a long string delimited by double braces. Csound will evaluate this long string before passing it to pyruni. During this evaluation, Csound uses C rules for evaluating literal strings; this means that you have to escape special characters like \n so that Csound will not interpret them during the string evaluation. So your code should be like this: Françoisscore = rowstring.rstrip('\\n').split(' 2016-11-07 14:45 GMT+01:00 Richard <zappfinger@gmail.com>: Some perfectly legal Python code generates a syntax error in pyruni: |
Date | 2016-11-07 15:17 |
From | Joe Knapka |
Subject | Re: string weirdness in pyruni |
Hi Richard, Cheers, - Joe On Mon, Nov 7, 2016 at 6:45 AM, Richard <zappfinger@gmail.com> wrote: Some perfectly legal Python code generates a syntax error in pyruni: It is always best to think of reality as perfectly normal. Since the beginning, not one unusual thing has ever happened. - Less Wrong
|
Date | 2016-11-07 15:48 |
From | Richard |
Subject | Re: string weirdness in pyruni |
Hi Joe, I did just that in the Python2.7 interpreter, and it works.. >>> li = 'a b c\nd b g\nx y z\n'
Richard On 07/11/16 16:17, Joe Knapka wrote:
score = rowstring.rstrip('\n').split(' |
Date | 2016-11-07 17:40 |
From | Joe Knapka |
Subject | Re: string weirdness in pyruni |
Escaped newlines are fine ('abc\nxyz'). Literal newlines are not ('abc xyy'), unless the string is triple-quoted. - Joe On Mon, Nov 7, 2016 at 8:48 AM, Richard <zappfinger@gmail.com> wrote:
It is always best to think of reality as perfectly normal. Since the beginning, not one unusual thing has ever happened. - Less Wrong
|
Date | 2016-11-07 18:15 |
From | Richard |
Subject | Re: string weirdness in pyruni |
Ok, I see your point about literal newlines. But I am only using
escaped newlines in this example. Richard On 07/11/16 18:40, Joe Knapka wrote:
|
Date | 2016-11-07 18:52 |
From | John ff |
Subject | Re: string weirdness in pyruni |
Depends on who is reading the string and who expands escaped characters
Sent from TypeApp
On 7 Nov 2016, at 18:16, Richard <zappfinger@GMAIL.COM> wrote:
|
Date | 2016-11-07 19:09 |
From | Francois PINOT |
Subject | Re: string weirdness in pyruni |
This is a tricky issue. The python code passed to pyruni is a long
string delimited by double braces. Csound will evaluate this long string
before passing it to pyruni. During this evaluation, Csound uses C
rules for evaluating literal strings; this means that you have to escape
special characters like \n so that Csound will not interpret them
during the string evaluation. So your code should be like this: Françoisscore = rowstring.rstrip('\\n').split( 2016-11-07 19:52 GMT+01:00 John ff <jpff@codemist.co.uk>:
|
Date | 2016-11-07 19:26 |
From | Richard |
Subject | Re: string weirdness in pyruni |
You are right, the double escape seems to work. Richard On 07/11/16 20:09, Francois PINOT
wrote:
|
Date | 2016-11-08 09:29 |
From | Francois PINOT |
Subject | Re: string weirdness in pyruni |
I added a note about it in the Strings article of the manual. François2016-11-07 20:26 GMT+01:00 Richard <zappfinger@gmail.com>:
|
Date | 2016-11-08 15:12 |
From | Richard |
Subject | Re: string weirdness in pyruni |
Great, thanks! Richard On 08/11/16 10:29, Francois PINOT
wrote:
|