How to setup PyCharm to not erase variables after execute? [duplicate] - python

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.

Related

Run Python-Script anywhere on Windows [duplicate]

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.

Half output shown in Sublime [duplicate]

This question already has answers here:
Can't send input to running program in Sublime Text
(5 answers)
Closed 7 months ago.
I wrote a factorial program in Sublime text editor. After executing the program using the shortcut key Ctrl + B only the first print statement is getting executed. However, I tried using the shortcut key Ctrl + Shift + B and the result is the same.
The problem is that proper execution is not achieved and I am unable to figure out the issue which is causing the problem.
Here is an image of the above-mentioned situation. As you can clearly see that I am following the conventions to execute the code. However, only the first line is executed.
Although I tried the same code in default Python IDLE I got the result. As such I don't think the code is wrong. Is it due to some IDE issue or have I not installed the sublime text editor properly.
Your code isn't wrong; the problem is that Sublime doesn't support interacting with a running program without extra work. Although it connects stdout and stderr to the output panel so that output your program generates can be displayed, it doesn't connect stdin to anything.
What you see is yourself typing 34 into the output panel, but your program doesn't see that and just sits in the background forever waiting for input that you can't provide until you kill it.
In order to run an interactive program like this from Sublime, you need to create your own sublime-build file that either opens an external terminal and runs the program there, or one that utilizes a package such as Terminus to open a terminal within Sublime and run the program there. Both of those require you to know what command you need to run in the terminal in order to run your program in order to set up the build.
An example of using Terminus for this task (using C and not Python, so you'd need to adapt it) can be found in this video on buffering and interactive builds in Sublime (disclaimer, I'm the author).

Write print statements including errors/warnings to file in Spyder [duplicate]

This question already has answers here:
IPython: redirecting output of a Python script to a file (like bash >)
(8 answers)
Closed 4 years ago.
I have a big python script where multiple print statements and warnings (e.g. deprecation warnings) are being printed to the IPython console. For debugging purposes I want to write all print statements and warnings/error to an output file. Is there a way to do this in Spyder?
I have tried in the console (but it won't create an output file in any of my directories):
runfile('pyfile.py',wdir='wdir') > output.txt
I know how to do this in the prompt:
python "directory\pyfile.py"> output.txt 2>&1
But being able to do this in Spyder would be way more convenient. I have conducted an extensive search here on Stack Overflow but none of the answers to previous questions gave me the desired result.
(Spyder maintainer here) You need to be aware that Spyder uses IPython consoles to run your code, so it's always better to search for what things you can do in IPython instead of in Spyder.
In this case, searching for ipython save stdout gave me the right answer in the first result, and that's an StackOverflow one.
In essence, you need to use the %%capture magic or a context manager (as the one mentioned in the answer above) and put runfile inside one of them to capture all stdout output in your program.

How to configure in .vimrc , execute current file python f9? [duplicate]

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 (%).

Issue with cx-freeze application: It is running for only 1 second [duplicate]

This question already has answers here:
Pygame and cx_freeze: segmentation fault
(5 answers)
Closed last month.
I made a game in python, and then exported it with cx-freeze. For some reason, when I try to double-click on the application it opens a command line for about a second and then closes. However, when I run it myself with just the python IDLE it works fine. What am I missing?
If it helps: I have graphic files in a separate folder called data and I'm using the normal python modules + pygame.
If you application is a GUI, you should freeze it with the "Win32GUI" base, so it doesn't open a command line. Have a look at an example in the docs.
I don't know why it's closing again - maybe it's failed to include something it needs. When you freeze it with the GUI base, any error messages should appear in a message box, which might help you work out what the problem is.

Categories