Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
How to Solve Brython Giving Error for the code value it got from Ace Editor

Please check the Images or Image links of my problem!

When I write my code in Ace Editor like this then Brython gives the correct result!

When I extend my code or the div resizes and hides the code like in this case 'pri' of print is hidden because of extending code, it gives an error

I have also tried wrapping the text but then also Brython gives an error!

My Brython and Ace Configurations are as follows!

function run() {
  const console = document.getElementById("console");
  const runner = new BrythonRunner({
    stdout: {
      write(content) {
        console.innerHTML += content;
        console.scrollTop = console.scrollHeight;
      },
      flush() {}
    },
    stderr: {
      write(content) {
        console.innerHTML += content;
        console.scrollTop = console.scrollHeight;
      },
      flush() {}
    },
    stdin: {
      async readline() {
        console.innerHTML += "\n";
        console.scrollTop = console.scrollHeight;
        var userInput = prompt();
        return userInput;
      },
      flush() {}
    }
  });
  var code = editor.getValue();
  runner.runCode(code)
}

function run_init() {

  if (document.getElementById("console") != '') {
    document.getElementById("console").innerHTML = '';
    run();
    console.log(document.getElementById('editor').innerText);


  } else {
    run()
  }
}
<button onclick="run()">run</button>
<div class='editor_class' id='editor'>print('Hello World')</div>
<div class='compiler_class'><textarea id='console' readonly></textarea></div>

<script src="https://ajaxorg.github.io/ace-builds/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="https://raw.githack.com/pythonpad/brython-runner/master/lib/brython-runner.bundle.js" type="text/javascript" charset="utf-8"></script>

<script>
  var editor = ace.edit("editor");
  editor.setTheme("ace/theme/vibrant_ink");
  editor.getSession().setMode("ace/mode/python");
  editor.setFontSize("16px");
  editor.container.style.height = "100px"
  editor.setOptions({
    enableLiveAutocompletion: true,
    copyWithEmptySelection: true,
    showGutter: true,

    useWrapMode: false, // wrap text to view
    indentedSoftWrap: false,
  });
</script>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your error was to use innerText on editor container instead of editor.getValue();, i have updated your code snippet and it works now.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!