I'm using the current python-mode to edit my source file in top window and a python inferior shell in bottom window to see the outputs (using C-c C-c from the source file, the cursor stays in the top, source file window).
Is there a way to navigate the traceback errors while still staying in the source code window?
Also - is there a similar way to navigate errors just in the file that was actually sent (i.e. not those errors coming from called external files)?
At the moment I either do M-g M-g to jump to line number, or switch to the python shell window and navigate there to the error I want to have a look at.
This would be a tremendous efficiency boost!
Thank you very much!
It turns out there are the functions [next/previous]-error bound M-g M-n and M-g M-p that do this (for some reason unmentioned in the python mode descriptions...). I'll keep the question open if somebody has a good solution to the second part - cycle only through the errors in the current file.
realgud that I wrote has a command (and mode) for shells called realgud-track-mode. When you invoke that, the debugger you are using will be prompted. For example it could be pdb (but I prefer trepan3k since I wrote that too)
At any rate once all of this is set up, then the command realgud:goto-lang-backtrace-line which is bound to C-c ! ! will parse the line in the shell window and bring the file at the location mentioned up in another buffer.
Related
I have written code in a New file window in IDLE.
When I run the code there is no output.
Instead a dialog box appears showing a window accessing Python Folder 37-32.
When i closed the dialog box and the file I tried to create a new simple code below but I when I ran the code I got the same Dialog box.
What is wrong?
sum = 2+3 print(sum)
I have attached a screenshot showing the code and the dialog box that appears when the Module is run
Before you can execute your code, your first need to save the file. Thats the dialog box that popped up.
You should have seen a popup box like below. Did you? Is is unclear?
Save Before Run or Check
? Source Must Be Saved
OK to Save?
[OK] [Cancel]
One reason to require saving is that exception tracebacks refer to the file and line of lines that lead to the exception.
If you had saved, sum = 2+3 print(sum) would be a SyntaxError.
You can run single statements in Shell without saving.
The RESTART lines says that the shell re-initialized the environment for executing your code.
You should normally not save your code buried in the installation Scripts directory. Better to make a directory in your user directory, for instance, C:/Users/yourname/py/.
Yes, one should usually open a new question for unrelated questions. But without access to your machine, it is hard to know what happened with 'new'. It may be that IDLE could create a file under .../appdate/.../Scripts/, but your code cannot. If the open call did not raise and exception, it was likely created somewhere. Until you are more experienced, better to use absolute paths, such as C:/Users/yourname/py/new.txt.
I'm starting to use pudb for Python debugging. It comes up fine, and I can step through, and it stops at breakpoints I put into code with pudb.set_trace(). So far so good. The main problem I'm having is this:
If I hit ^X to get to the command-line pane, I can type executable lines or variable names, like running interactive Python, but the slightest typo (or experiment in search of other commands, or request for help()) lands me in a state I can't recover from. Even Control-c (as claimed at https://docs.python.org/2/tutorial/appendix.html#tut-interac) just shows up as "^C" and does nothing.
For example, if I type "help()", it prints some Python (not pudb) help, redisplays "help()" in yellow, and then I'm dead in the water. Backspace won't affect the "help()" that's displayed, and ^H just gets displayed as caret + H -- until I hit return, when it seems to be appended to "help()" as literal backspaces, since I can make part of all of "help()" disappear. I can type anything after "help()", but I always get:
SyntaxError: unexpected EOF while parsing
followed by a redisplay of what I had typed. How do I "clear" this state and get back to the normal command line, short of quitting my terminal program?
Using Terminal on Mac OS X 10.9.5, though I can also try Linux.
Your description points not to a problem with pudb but rather to a problem with behaviour of Backspace on the Terminal you're using.
Please try changing this behaviour so it's sending the proper Backspace. This could be helpful: http://fredericiana.com/2006/10/16/fixing-backspace-and-delete-for-ssh-in-os-xs-terminalapp/
Then, you should be able to enter pudb's full screen Python interpreter by '!' and leave it by Control-D.
A "small" Python command line inside pudb's interface can be accessed by Control-X and you can leave it by Control-X. In this one you have three other shortcuts which also let you manipulate the command line: Control-V - insert new line and Control-N/Control-P to browse command line history. If any of these is not working it's rather an issue with the way the Terminal treats these shortcuts and not in the way pudb does.
Short version: how can I tell ghostscript, "keep going, even if you find garbage" when running in batch mode?
Longer version: I have a bit of Python code on Windows that uses check_subprocess to call Ghostcript. (I'm merging several PDFs into one).
popenargs = [r'C:\Program Files\gs\gs9.15\bin\gswin64.exe'
,'-dBATCH'
,'-dNOPAUSE'
,'-dLastPage=5'
,'-q'
,'-sDEVICE=pdfwrite'
,r'-sOutputFile=C:\temp\bar.pdf'
,r'c:\temp\a.pdf',r'c:\temp\b.pdf']
subprocess.check_call(args)
While things are running, you see the Ghostcript window pop up and disappear, and that's OK with me.
The problem occurs when ghostscript encounters a corrupted PDF. It leaves the window up, with some details about the error, and instructions to close the window manually. This is problematic, because it leaves the python script hanging. I don't want that -- if an error is found, that's OK with me -- I just want the file skipped and for things to keep moving.
Is there any way to tell Ghostscript to do what I want?
I would have to see an example to say for sure, but the simple answer (on Windows) is no.
You could, of course, use gswin64c.exe instead, its much more suitable for automation anyway.
I had a python code and I used Pyinstaller to make it a stand-alone .exe executable.
In my code, I use "print" function to output result.
However, if the result is really long, (several screen page long) the result is cut short because the limitation of the console, I can scroll up but I guess the total length of the viewable text region is limited. (I am running my .exe in Windows)
Is there a way to extend the visible range so I can see all my output?
Thanks!
================
update:
I agree with #supremefist that it is the shell that is limit the visible range.
Is there a way to pass parameters to the shell so that when I double click it in Windows, the view range is extended.
Also, if it is possible, I would like to have my executable robust across different OSs. I am trying to write a small program and my target users maybe inexperienced computer users.
================
update2:
Now, I understand that Pyinstaller is only for Windows, previous update for different Oss is completely wrong.
The good news is that I switch to Qt and this problem goes away as I am now displaying my result in a window rather than a shell console.
I don't think the limit is related to PyInstaller, but to the constraints being set on your windows shell. You could try changing your shell settings by doing the following:
Open a windows shell by either running 'cmd' or by finding it under Accessories in your Start Menu.
Right click on the title of the shell window and select Properties.
Increase the screen buffer height setting under the 'Layout' tab to a large number. Something like 9999.
Re-run your program, you should see a much longer history of text.
I want to collect data and parse it eventually from an open window in linux.
An example- Suppose a terminal window is open. I need to retrieve all the data that appears on that window. After retrieval, I would parse it to get specific commands entered.
So is it possible to do that? If so, how? I would prefer to use python to code this entire thing.
I am making a guess that first I would have to get some sort of ID for the open window and then use some kind of library to get the content from the window whose ID I have got.
Please help. I am quite a newbie.
You can (ab)use the assistive technologies support (for screen readers and such) that exist in the toolkit libraries. Whether it will work is toolkit specific—Gtk and Qt have this support, but others (like Tk, Fltk, etc.) may or may not.
The Linux Desktop Testing Project is a python toolkit for abusing these interfaces for testing GUI applications, so you can either use it or look how it works and do similar thing.
I think the correct answer may be "with some difficulty". Essentially, the contents of a window is a bitmap. This bitmap is drawn on by a whole slew of primitives (including "display this octet-string, using that encoding and a specific font"), but the window contents is still "just pixels".
Getting the "just pixels" is pretty straight-forward, as these things go. You open a session to the X server and say "given me the contents of window W" and it hands it over.
Doing something useful with it is, unfortunately, a completely different matter, as you'd potentially have to (essentially) OCR the bitmap for what you want.
If you decide to take that route, have a look at the source of xwd, as that does, essentially, that.
Do you have some sort of control over the execution of the terminal? In that case, you can use the script command in the terminal session to log all interaction to a file and then read and parse the file.
$ script myfile
Script started, file is myfile
$ ls
...
$ exit
Script done, file is myfile
$ parse_file.py myfile
If the terminal is running inside of screen, you have other options as well. Screen has logging built in, screen -X sends commands to a running screen session (man screen).