This question already has answers here:
Running Python code in Vim
(25 answers)
Closed 5 years ago.
I'm newbie in this editor but it's complex to configure vimrc. I know and understand that everything stay there but I don't understand how to configure, specifically the code. On the other hand, I am writing Python code using Vim. Every time I want to run my code, I type this inside Vim
:w !python
This gets frustrating, so I was looking for a quicker method to run Python code inside Vim. If somebody can I help me, I would be very grateful.
You've very close. The following works in my config:
nnoremap <F9> :w<cr>:!python %<cr>
First, it enters the command to save the file (:w). Then it tells the shell to have python (!python) run the current file (%).
Related
This question already has answers here:
How do I make a python script executable?
(6 answers)
Closed last year.
Say I have the program program.py in a non-root directory. Thus, in order to run the program, I have to type python3 program.py every time. Is there a shortcut that I can enable in my unix environment where I type a specific command for a specific program to run. I.e. for the above, I want to just be able to type program and have the program run.
I am not greatly familiar with unix but I believe this has something to do with adding something to your path which I am unfamiliar with this method. Any references and/or support is greatly appreciated!!
Thanks!
Add this to the top of your file.
#!/usr/bin/python3, or wherever your install is.
Then chmod +x your_file.py.
This question already has answers here:
PyCharm debug console not working
(10 answers)
Closed 1 year ago.
I'm starting on Python development using PyCharm and I want not erase the variables content after execute de file, like do Spyder to iteracte over data on Python console.
Like can see on the print the variable resultado is not available on window to set content.
resultado is a pandas data frame, there are some way yo see the CSV table on macOS instead see it on terminal?
PS.: I'm using Python 3.9 on venv.
The „Python Console“ here is basically just your typical Python REPL.
It doesn’t interact with the code you have written in the file; it’s basically an empty shell. That’s why it is unaware of your variabel.
You could run your file from the shell so it’s in context.
But most likely you want to run your file with the interpreter by using the little green arrow in the top right corner and the Python Shell tab on the bottom just for quick prototyping or to try stuff quickly as that’s more what it is intended to do.
This question already has answers here:
How to run a Python script portably without specifying its full path
(4 answers)
Closed 3 years ago.
I am looking for a way to run a python script from anywhere.
I have seen this solution but as it is based on Linux I am looking for a way on Windows (10).
Basically what I want to do is, execute a script with a given parameter. Because it could be disturbing for the user, I am using a .pyw-file extension to hide the console.
Things that came to my mind:
a PATH-Variable
PowerShell-Script
Batch-file
Sadly I am not familiar/experienced with neither of those, so I can't really tell if these ideas even provide a way to do that.
Any answer is appreciated.
Edit: I would like to make the command as short as possible for the client so it is not necessary to write a novel to exec one simple task.
Another Edit:
I want the user/client to open its cmd/ps and use a command which executes my python-script, which is not in this directory he is, when opening the cmd. So the script is somewhere on his computer, but shall be executable by command from anywhere.
try to create a "code.bat" file with this command "python script.py" inside your .bat file then add the "code.bat" to your path in your environments anytime you want to run the script just type code in your shell.
This question already has answers here:
How to keep a Python script output window open?
(27 answers)
Closed 3 years ago.
In my Python script, I create a .bat file (many actually), and I run them via
os.startfile(blah)
Everything works like expected, however, those terminals die after finishing. I want to keep them open, so that I can type more commands manually in those opened terminals.
How?
You could try using the cmd command to run the batch file, and then use command line arguments for cmd to modify its behavior. For example:
os.startfile("cmd.exe /k blah.bat")
Documentation of the available command line arguments can be found here:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd
This question already has answers here:
Pycharm and sys.argv arguments
(12 answers)
Closed 5 years ago.
I recently just downloaded PyCharm, and I want to get to know it better, however, codes that I would normally run through the terminal, like an argument parser, I no longer know how to do. Here is an example of what I would put into my command line:
python read_in_data -w wide_data_set -s row_number -o output_path
This would then run the code with my given arguments.
Any basic tips on PyCharm would be helpful, as I am very new to it.
(Top of your screen) Go to Run > Edit Configurations, then enter the command line arguments into the "Script parameters" box. These will then be used when you run the code.
For basic tips/an intro to PyCharm - see the tutorial videos on their website.