Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi line Python code prevent escape
In the code of the following post, because the Python code is only a few lines, it can be executed successfully

But if there are many lines of Python code, there will be many symbols to escape, which will be very troublesome. For example, the following code:

C# code:
// script "ipy_no.cs" /*/ r Libraries\IronPython.dll; r Libraries\Microsoft.Scripting.dll; r Libraries\Microsoft.Dynamic.dll; /*/ //.
using Au; using System; using Microsoft.Scripting.Hosting;
using IronPython.Hosting;
partial class Script : AScript { [STAThread] static void Main(string[] a) => new Script(a); Script(string[] args) { //;;;

ScriptEngine engine = Python.CreateEngine();

string code = @"# -*- coding: UTF-8 -*-
import httplib
import urllib
import socket
import time
params = dict(
    login_token="31e250c75", # replace with your API token
    domain_id=79051040, # replace with your domain_id, can get it by API Domain.List
    record_id=603739834, # replace with your record_id, can get it by API Record.List
    sub_domain="help", # replace with your sub_domain
current_ip = None

def ddns(ip):
    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/json"}
    conn = httplib.HTTPSConnection("")
    conn.request("POST", "/Record.Ddns", urllib.urlencode(params), headers)
    response = conn.getresponse()
    print(response.status, response.reason)
    data =
    return response.status == 200

def getip():
    sock = socket.create_connection(('', 6666))
    ip = sock.recv(16)
    return ip

ip = getip() 

var paths = engine.GetSearchPaths();



In qm2, it is very simple to prevent escape multiple lines of code,  For example, the following code, in qm3, Is there any good solution? Thanks in advance

Macro Macro3
Copy      Help
str code = 
;# -*- coding: UTF-8 -*-
;import httplib
;import urllib
;import socket
;import time
;params = dict(
;;;;;login_token="31e250c75", # replace with your API token
;;;;;domain_id=79051040, # replace with your domain_id, can get it by API Domain.List
;;;;;record_id=603739834, # replace with your record_id, can get it by API Record.List
;;;;;sub_domain="help", # replace with your sub_domain
;current_ip = None
;def ddns(ip):
;;;;;headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/json"}
;;;;;conn = httplib.HTTPSConnection("")
;;;;;conn.request("POST", "/Record.Ddns", urllib.urlencode(params), headers)
;;;;;response = conn.getresponse()
;;;;;print(response.status, response.reason)
;;;;;data =
;;;;;return response.status == 200
;def getip():
;;;;;sock = socket.create_connection(('', 6666))
;;;;;ip = sock.recv(16)
;;;;;return ip
;ip = getip()
Maybe C# 10 will have this or similar proposal implemented.

Now, if the string is big, maybe better let it be in a file, which can be added to the QM3 workspace and edited in QM3. Also then it can be added to resources and loaded from there as string.

Or create a script to replace all " with "" or '.

Forum Jump:

Users browsing this thread: 1 Guest(s)