Log in

View Full Version : Syntax for linebreaks working in Eval()?


tin3tin
24th August 2012, 12:21
How do I add linebreaks to a string which can run by eval()?

Ex. code:
video= \
directshowsource("C:\MATERIAL\VJ0K006W.avi")
Video

My (not-working) attempt:
My_string="""video= \"+chr(13)+chr(10)+"directshowsource("C:\MATERIAL\VJ0K006W.avi")"+chr(13)+chr(10)+"Video"""
eval(My_string)

[EDIT:
This actually works:
My_string="""video= directshowsource("C:\MATERIAL\VJ0K006W.avi")"+chr(13)+chr(10)+"Video"""
eval(My_string)

So to refrase the question. How do I make multiple line commands with "\" to be used in Eval()?

This doesn't work:
My_string="""video=" +CHR(92)+chr(13)+chr(10)+"directshowsource("C:\MATERIAL\VJ0K006W.avi")"+chr(13)+chr(10)+"Video"""
eval(My_string)
]

librarian
24th August 2012, 13:00
Use Chr(92):
My_string= "video = "+chr(92)+chr(13)+chr(10)+"directshowsource("+chr(34)+"C:\MATERIAL\VJ0K006W.avi"+chr(34)+")"+chr(13)+chr(10)+"video"
eval(my_string)

e.g.:

My_string= "video = "+chr(92)+chr(13)+chr(10)+"directshowsource("+chr(34)+"C:\MATERIAL\VJ0K006W.avi"+chr(34)+")"+chr(13)+chr(10)+"video"
my_string2=chr(92)+chr(13)+chr(10)+"blur(1.58)"+chr(92)+chr(13)+chr(10)+"blur(1.58)"
eval(my_string+my_string2)

tin3tin
24th August 2012, 13:10
Ahh, great! Thank you very much!!

Gavino
7th September 2012, 10:23
There is no need to use chr(92) as '\' has no special meaning inside a string.
Your original problem was that you were attempting to close a triple-quoted string with a single quote.
Instead of:
My_string="""video= \"+chr(13)+chr(10)+"directshowsource("C:\MATERIAL\VJ0K006W.avi")"+chr(13)+chr(10)+"Video"""
eval(My_string)
you should have used:
My_string="video= \"+chr(13)+chr(10)+"""directshowsource("C:\MATERIAL\VJ0K006W.avi")"""+chr(13)+chr(10)+"Video"

Note also that newlines can be included literally inside a string, so you can also avoid the chr(10) and chr(13) by using:
My_string2="""video= \
directshowsource("C:\MATERIAL\VJ0K006W.avi")
Video"""