1

I want to use external tools to automate the internal execution of presently-being-authored scripts by keyboard shortcut. The only thing I can find on this is here. But I think it must be out of date because it's producing a syntax error that I can't find any useful information on. I know python3 needs parentheses after print, so I tried with and without, but the same error is produced. Strangely, print commands.getoutput(line)) produces a syntax error recognizing the missing opening parenthesis.

Also I changed the 'comment'(I guess) at the top of the tool to python3 thinking the interpreter would handle whatever parentheses indiscretion was occurring a little more gracefully, but that's a no go because commands is apparently defunct now.

Obviously I want the code that will do what I want, but answers shedding light on the error as well are preferred. I care to know what's actually happening.

EDIT Proof that my syntax is accurate

EDIT I realized that the issue might be something to do with my code, because previously I was working with a multi-page length script, so I opened a new document and tried the following simple statements. The results are interesting but tell me nothing.

Input

True == True

Output

Running tool: run source

sh: 1: True: not found


Done.

Um, okay.


Input

True==True

Output

Running tool: run source



Done.

Oh! Maybe it did the calculation but it just didn't print it!


Input

print(True==True)

Output

Running tool: run source

sh: 1: Syntax error: word unexpected (expecting ")")


Done.

... Back to square one I guess.


Input

print True==True 

Output

Running tool: run source

sh: 2: Syntax error: ";" unexpected


Done.

What f***ing semicolon?!

EDIT So I thought I had the problem worked out below. Not so much it turns out... I've just realized this doesn't answer the question! I asked if it is possible to send selected code to the gedit TERMINAL for execution. The idea was to have an IDLE like set up where I could arm the terminal with classes, functions and variables from my document and then interact with it live. External tools make use of an 'Output panel' which gets put in a tab beside the embedded python terminal. It executes the code behind the scenes and then displays the full output all at the same time. It can't be used to get user input.

1
  • It's not a gedit issue - you got Python 3's print syntax wrong - the correct one is: print(commands.getoutput(line)) - You need both an opening and closing bracket
    – user423626
    May 6, 2016 at 16:40

1 Answer 1

0

I have no idea why the errors read the way they did, but by pure luck I did author a functioning code...

It goes like this:

Plugin

#!/usr/bin/env python3

import sys

exec(sys.stdin.read())

-Shortcut key: Alt+R ---or whatever you're comfortable with

-Save: Nothing

-Input: Current selection(default to document)

-Output: Display in the bottom pane

-Applicability: |All documents |Python 3

Input

print(True == True)

Output

Running tool: run source

True

Done.

EDIT I've just realized this doesn't answer the question! I asked if it is possible to send selected code to the gedit TERMINAL for execution. The idea was to have an IDLE like set up where I could arm the terminal with classes, functions and variables from my document and then interact with it live. External tools make use of an 'Output panel' which gets put in a tab beside the embedded python terminal. It executes the code behind the scenes and then displays the full output all at the same time. It can't be used to get user input.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .