Newbie here. I noticed that the >>> that usually precedes the colon in the Python Console has been replaced by In[#], in which # increments with each command.
I can still run code, but would like to know why this changed, whether it matters, what they mean, etc.
Related
I hope this makes sense. When using the IDLE python shell and typing the commands one by one, there is an output or response to most lines of code typed.
When writing a script and then running that script in IDLE I don't get to see the same output in the shell, is there a way of enabling it, or a line of code to add to my script so it displays?
Thanks
A feature of both standard interactive mode and the IDLE Shell (and presumably of other Python IDEs) is that the value of expressions entered in response to the >>> or other interactive prompt is echoed on a line below.
When running a script, the value of an expression statement is not printed. This is because such expressions are often included in files for their side effects, and because output may not be wanted. One must explicitly print() or sys.stdout.write() to see the result . So
>>> 2+3
5
must be written, for instance, as print(2+3) in a program executed all at once, whether from any editor or from a command line. (In other words, this question is not really IDLE specific, although it is a common one from beginners, who often use IDLE.)
If this is not your problem, we need much more information to help.
I'm doing experience with my first small applications, essentially data viewers based on Pandas and matplotlib, using PyQt for the GUI part.
What I find now difficult is to understand what goes wrong in my code, because the error does not get propagated to the iPython console I launch my script from.
It simply won't do what's expected, but there is no information as to 'why'.
To fix ideas, let's say I have a button that should plot a certain curve to the canvas. If there's a fail in the indexing operation of the data, therefore nothing can be plotted, then nothing will appear on the canvas, but I'll get no traceback that actually index so-and-so wasn't to be found.
Using the debugger proves quite cumbersome, too.
I had a situation where, while running my main(), I could interact with the IPython shell and do things like:
main.my_plot_function()
from which I would get a standard output, and see what is wrong. Although sub-optimal, this did the trick.
I had to reset Spyder this morning (wasn't launching on Windows), and since then, when I launch my script, the console is unresponsive. So I can't do `main.my_plot_function()' anymore.
Generally speaking, is there a way to instruct Spyder or the console that I want to see what's going on in the background? Some "verbose" switch?
I am not sure what you mean by wanting to know what's going on in the background. I assume that you wish to know at many points in the code, what the variable types and values are and/or where the current point of execution is.
There are two options:
1) Use print statements wherever you need to know what's going on. For example, if you have a plot function, simply put some print statements inside the function to print out the sizes of the lists/arrays being plotted etc. You can also look for useful functions in this regard, i.e., type() to print out the type of a variable to make sure it is what you think it is, print(locals()) to print names and values of all local variables etc.
2) Use pdb to introduce break points and run your main script from the command line. This will stop the script execution where you want and from the pdb console, you can inspect the data-structures. There are of course other debuggers you can use, such as pudb (with a basic GUI and some extra features than pdb).
There is no general "verbose" mode in spyder or any other Python IDE I know of.
I've recently started having a weird bug with my python scripts. It seems like it's syntax switches between python 2 and 3 randomly when running the script. For instance, I'll write a script using the input() command, and it'll work fine for a couple hours, then start giving me an error even if I don't change a single thing in the code, and want me to switch input() to raw_input() in order for it to work again.
And the same will happen in reverse. I'll write a code with raw_input() since it doesn't like input(), and a few hours later it'll make me switch it. It does this with all syntax, not just the inputs. The other main one is the print command. It'll switch between wanting parenthesis around the print statement, or not.
But when I run python --version, it always returns only Python 3.5.1. Anyone have a fix for this? It's getting annoying having to change my scripts every few times I run them.
Basically, after getting Sublime text 2 and sumblimeREPL up and running, I am having issues when I send code. For instance, in the below screenshot, I enter the code on the left line by line (ctrl+,l), or by block/selection but nothing shows up except the output. In[3]-In[6] I was attempting to run the x and y lines only. Is this the intended behavior? I would have assumed yes, except that all the output is being displayed on the input lines. The only other language I have tried so far is R, and it does not have this issues. Also it is the same issue in both python and ipython. Any ideas?
First off, I'd strongly suggest upgrading to IPython 1.1.0, as while the issue likely isn't related to the older version, it's well worth the upgrade, especially if you use it a lot.
If you open Preferences -> Package Settings -> SublimeREPL -> Settings - Default, you'll notice that the last line is "show_transferred_text": false. I'm on OS X, but when I have this set to false, I see the same behavior you do - the result of the expression printed on an In [#] line, with another blank line following it, ready for the next expression. However, if I set this variable to true (by copying the entire contents of the file, opening Preferences -> Package Settings -> SublimeREPL -> Settings - User, pasting everything in there, then changing settings and saving), then I see different behavior when transferring a line: The expression is printed on the In [#] line, and the result is printed below.
The reason you didn't see any results when evaluating the assignments to x and y is because nothing is returned, by default.
By way of explanation as to why the Python/IPython REPLs work this way, while the R one doesn't, is because SublimeREPL is very modular, and for the most part is just a thin wrapper surrounding native code. Therefore, the exact mechanism of transferring and displaying data may differ from Python to Ruby to R to Clojure, for example, and you may see slightly different behaviors.
I wanted something more interactive. I wanted both the In[#] with text followed by an Out[#] with the output. I also did not want to switch from my source code to REPL just to get a damn Out[#].
Like this, for example...
The solution I came up with is a lot more complicated than the post above but you get that interactive feel that one gets when using R with Sublime Text. You can find my solution here: https://stackoverflow.com/a/27562036/3987905
Be sure to keep "show_transferred_text": false. Enabling it appears to mess up the plug-in. Hope it helps.
If I'm using a python interpreter under EMACS, then I've got various ways of evaluating code, for instance just typing it in at the REPL (Inferior Python) If that code produces too much output, then EMACS freezes solid and has to be killed.
This will do it, for instance.
[[[False] * 200 for i in range(3)] for j in range(200)]
There's no problem at all if python's running in a terminal. It just prints out False 120000 times and gives me the prompt back.
Is there any way to either limit the amount of output the inferior python process produces, or to get EMACS not to explode when faced with large outputs?
In clojure, for example, I can use *print-length* and *print-level* to solve this exact same problem.
Repeated calculations by comint-mode are considered the cause.
As for python-mode.el checked in a solution WRT
https://bugs.launchpad.net/python-mode/+bug/1253907
which makes it work from inside a print in source-buffer, not from shell.
It comes with a couple of new commands prefixed "py-fast-".
Alternatively new option py-fast-process-p must be `t'.
Maybe give it a try:
https://launchpad.net/python-mode
However, with python-mode.el and M-x IPython RET, it doesn't occur, runs nearly as fast as in console.
BTW ipython.el should not be needed.