iteratively and interactively writing and testing python code - python

I'd like to iteratively write and test my python code in the Python console. I can't find a way to easily load what i've got written in the editor (somefile.py) into the Python console in Pycharm. Is there a trick to doing so?
Pycharm will let me run the entire script but that's not useful because i want to build up my state in the shell by experimenting with the functions and data i've got in the environment (kind of like how a lisp programmer would use a REPL).

Pycharm have this alt-shift-E option.
This way you can write in the editor, select the lines you want to run and run them by alt-shift-E.
I use it all the time, although I find a lot of people not fameliar with this option.

Related

How to run a "section" of a python script, like Matlab

When using vim (or any other text editor) for python scripts, is there a way to run a section of your script alone?
Matlab has a feature where beginning a line with %% splits the lines of code that follow into a section of its own, that can be run independently. Is there a way of achieving this without having to use iPython? Even if the solution is a bit hacky, it would be an improvement over what I currently am doing, which is commenting out blocks that I don't want to run.
A generic solution would be vim-slime: https://github.com/jpalardy/vim-slime
SLIME is an Emacs plugin to turn Emacs into a Lisp IDE. You can type
text in a file, send it to a live REPL, and avoid having to reload all
your code every time you make a change.
Vim-slime is a humble attempt at getting some of these features into
Vim. It works with any REPL and isn't tied to Lisp.

running a python script when i turn my pc on

I created a python script to control the RGB of my keyboard and my mouse and i want it to start when i turn my computer on. I have 2 solutions but i don't know which is the best.
the first solution is to build my script and run the executable on startup
the second solution is to run directly the python script with python.
the first solution is a little bit annoying because is i want to change the code, i need to rebuild my script. and also when i tried to run the exe (created with pyinstaller), it didn't work (because of the dlls i think)
the second solution is better if i want to change the code later, but i don't know how it would react if i run another python script (i don't even know if it's possible to run 2 python instances at the same time.)
so if you have any idea on which solution to choose, how to build a script using dlls with pyinstaller or if i can run multiple python instances (maybe i can run multiple venvs), feel free th help me.
PS: I tried to be clear but as i didn't speak english very well i don't know if you understood my issue.
Using windows : https://www.geeksforgeeks.org/autorun-a-python-script-on-windows-startup/
Using Linux : follow this https://stackoverflow.com/questions/24518522/run-python-script-at-startup-in-ubuntu#:~:text=Put%20the%20command%20python%20startuptest,and%20put%20the%20command%20there

Execute Python code line by line, like VBA?

I'm new to python and I'm having fun. So far I've only been on the road in VBA and SQL, but one thing bothers me. Is there no feature that goes through the code line by line like in VBA? This has always helped me a lot with VBA (F8), I could check the value of the variable on the fly (hold mouseover), i could check the whole code better and see where exactly it is running on a bug. Is this function not really available in python? I use PyCharm as IDE
Thanks!
You may try the following command: python -m pdb <script.py>. It will run the script in the Python debugger where you can traverse your code step by step.
There is nothing like VBA/VB6 IDE for python, unfortunately. Microsoft's IDE is simply unmatched in terms of debugging convenience. As a language, Python is more powerful, but good debugging solution is yet to come, you can't chance lines execution order or alter code on the fly in the debugger.

visual studio code equivalent of python -i

I am looking for the equivalent of python -i in VScode.
That is, a way to open a terminal (or run in the included terminal) the program that is open, and use the program in the read-print-eval loop, being able to call functions and inspect variables freely.
I searched for this plugin without success.
I need it to be around as simple as pressing f5 and typing something. I want to use it to teach, and my students already have many difficulties with algorithms and coding. Also, easy instalation would be ideal. I am sorry for being that 'demanding', but classes are huge and the chance of getting everyone to do a procedure go down fast with the size of the procedure.
I would not mind creating such a utility myself, if someone will point me the way, and then uploading it to whatever 'store' VScode downloads its plugins from.

Python Workflow like RStudio?

I use Python as my main programming language, sometimes switching to R for quick data-analysis tasks due to it’s huge library for statistical programming purposes (although pandas for python is great!). I guess that most R-Users go for R-Studio, which is like an IDE for R. There are probably hundreds of IDE’s for Python, but i’d like to stick with VIM and IPython. Although there is the vim-ipython-plugin, i can’t recreate the R-Studio workflow, which is mainly:
Write code in the source-editor
"push" or execute it within the console window via CTRL-Enter
after that, the results get displayed in the console window or the plotting window
When using the vim-ipython plugin, you can execute vim-lines via CTRL-S, but the results in the running IPython-Kernel/QTconsole are not updating. Instead, the output goes directly to a VIM window (<leader>s opens it, but the window closes all the time and isn´t able to display inline-graphics, like the ipython-qtconsole does).
I’m sure this isn’t a new "problem", but is there any setup for VIM and (I)Python, which mimics the RStudio behavior and integrates both the editor and the interactive interpreter like modern IDE’s do? Copying text from vim to the interactive interpreter can’t be the optimal solution, right?
The canonical way of doing this in vim is to run vim inside a gnu-screen or tmux session with the REPL in a second screen in the session. You can then use vim-slime to send code from vim to the REPL.

Categories