Can't see output, only in terminal - python

I'm trying to write some Go code in VScode.
I have the Code Runner (v. 0.9.9) and Go (v 0.10.2) extensions.
I tried to run the following:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
In the output tab I got:
[Running] go run "/home/joe/code/test.go"
[Done] exited with code=0 in 0.236 seconds
Which does not include the output of the Println statement. While if I run it from terminal (from VScode even), I get:
joe#HP-Laptop-15-bs0xx:~/code$ go run test.go
Hello, World!
This, by the way, repeats itself with other languages I've tried as well (like Python).
How can I fix this so I can get the actual output to the output tab?

For output tab only execute go test without verbose command. you must be add -v argument to go test config.
Add this to settings.json on VSCODE
"go.testFlags": ["-v"],

Related

how to remove std redundant output of python program in vs code ide?

I'm using vs code for python development. I need to unclutter some std output of path whenever i run my python code.
Here below i run "Hello world" in a file any2.py - is there way to remove all that lengthy path before the actual output?
PS C:\Users\erjan\Desktop\kkkk> c:; cd 'c:\Users\erjan\Desktop\kkkk'; &
'C:\python38\python.exe' 'c:\Users\erjan\.vscode\extensions\ms-python.python-2022.12.1\pythonFiles\lib\python\debugpy\adapter/../..
\debugpy\launcher' '55841' '--' 'c:\Users\erjan\Desktop\kkkk\any2.py'
Hello world!
I dont know what this /debugpy/..adapter//launcher is all about, it is sometime tiring to read unrelated output
\debugpy\launcher'
You are using debug mode:
You can try Run Python File, in front of command, only the path of Python interpreter will be displayed.
You can also try code-runner extension.
Then change the settings:
add the following code to this setting.json:
"python": "python",
Here is the result in terminal:

Unable to open my source code a second time with `python -i`

When I first start bash I can open my code like so:
$ python -i index.py
That file is open, but when I try again this happens:
>>> python -i index.py
File "<stdin>", line 1
python -i index.py
^
SyntaxError: invalid syntax
If I close bash and start again it works. What am I doing wrong?
You can't run terminal commands from the Python REPL.
You can tell you're in the REPL when you see >>> as opposed to $. This means you can run Python code there, but not shell/terminal commands (like the python command).
To exit the REPL, use Ctrl + Z or type exit() and press enter. This will bring you back to the regular terminal.
In addition, I'd recommend running just python index.py rather than python -i index.py in most cases.
The added -i means that you'd like to stay in the REPL to inspect the results after running the index.py file. It allows you to continue running additional Python code after the index.py file has finished its execution.
It looks by the three >>> that you are in the python console not in bash itself. If you type exit() you should get back to bash, and then you can try the code again.

IPython magic commands work in Python console, but not in the "Run" or "Debug" script mode

I have two python scripts read.py and main.py. The content of main.py is:
%run -i read.py
However, when I want to run the main.py as a script or debug it with icons in the upper right corner, I get the following error:
%run -i read.py
^
SyntaxError: invalid syntax
I edited the configurations of the main.py file so that its interpreter is Python version from conda environment. As in subject, I have no issues running this particular line %run -i read.py from Python console. What may cause this problem?

Start python file in Swift

I want to start a pythonscript by pushing a Button in a swift macOS application. I come up with:
let process = Process()
process.launchPath = "/usr/bin/python3"
process.currentDirectoryPath = "\(NSHomeDirectory())" + "/PycharmProjects/untitled5"
process.arguments = ["myscript.py"]
process.launch()
but I get "launch path not accessible" error by executing. If I change launchPath to:
process.launchPath = "/usr/bin/python"
everything works fine, but now I getting python compiling errors because myscript is written in python3.6.0, I have to use python3 because of using a library.
When I open Finder and go to "/usr/bin/python3" it says not found, but python3 is installed, I used it in Pycharm and I'm also able to start python3 in terminal.
In terminal "python3 ~/PycharmProjects/untitled5/myscript.py" works.
On your terminal type
which python3
this will return the path that is accessed when you run python3 from the command line

python script to send commands to vim (mvim)

I wrote a very simple vim plugin and python script trying to test some communication between the two. My vim-script looks like this:
function! HelloWorld()
silent :!python helloworld.py
endf
nmap <C-P> :call HelloWorld()<CR>
then my python script looks like this:
import os;
os.system( 'mvim --servername VIM -u NONE -U NONE --remote-send \"<C-\\\\><C-N>:echo \'Hello World!\'<CR>\"' )
If I am in vim and press , use the ":call HelloWorld()" command, or just type ":!python helloworld.py" from the same or another mvim or vim instance, nothing happens. However, if I call the script from the command line separately, mvim responds appropriately: shows "Hello World!" along the bottom.
Does anyone have any idea why it is not working when called from vim?
Try replacing
silent :!python helloworld.py
with
silent :!(sleep 0.5s && python helloworld.py) &
redraw!
(the point is in returning to vim before remote command arrives). If it works, then the problem is in processing remote commands while receiving shell output. You can also try another workarounds:
call system('python helloworld.py')
,
call system('python helloworld.py &')
and
pyfile helloworld.py
(Note that the last one requires vim compiled with +python feature and also alters the state of python interpreter used by vim).
By the way, use system() call instead of ! when you don't want to see the script output. Also use redraw! after silent !.

Categories

Resources