Hi Andy,
One pitfall is that debugging does not work (i.e. execution does not stop at a breakpoint) for breakpoints in code that was executed as a cell. Could this be the problem?
Regards,
Almar
--
You received this message because you are subscribed to the Google Groups "Interactive Editor for Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iep_+uns...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I don't think the problem is related to being executed as a cell, although I don't know precisely what that means. I assume it means that the code which contains the function with the breakpoint in it was "compiled" by using an "execute cell" command. ...
Since I posted the inquiry, I've experimented with pdb. After initially having similar problems with it, I did notice that the reason I could not set a breakpoint properly was because the file being debugged was in a folder which was not on Python's search path. Things started working when I modified the path to include the folder containing my source file. Could there be a similar issue with IEP debugging?
A more general but related question: Should I just be able to "execute selection" on a selection which contains a function definition with breakpoint in it, and then invoke that function from the interpreter window, and hit the breakpoint? I've tried both that, and "execute file" on with the current file containing the function definition with the breakpoint. In this case "current file" means the active tab of the editor pane of the IDE. Nothing seems to work.
Pdb breakpoint debugging did seem to work once I got the file on the search path, but doesn't seem integrated with the IEP based debugging. Are pdb and IEP debugging completely different animals?
> I fixed the problem with IEP not running by deleting the whole folder heirarchy and recopying from the dmg file.
>
> I then got debugging working using "execute file". Hooray!
Yah!
> I've noticed that what happens when you run code by "executing" from the menu is very different from what happens when you "import" that file from the shell. All sorts of namespace things are different, and in ways that I don't understand because I'm new to Python. I think the differences are a very good thing in that I suspect they protect you from name collisions by not polluting the global namespace by executing import statements within your source file in a global scope, in the case where the file with the import statements is itself being imported. Am I right about this? I know the sentence isn't that clear but I hope you get the gist of the question.
Yes, this a python thing. Python makes much use of namespaces, which is a good thing. Basically, every module has its own namespace. And you can get access to a module by importing it (i.e. bringing it in the current namespace). There is also a “main” namespace corresponding to the namespace of the script being run.
I’m not sure what you’re trying to do, but its generally good practice to separate scripts from modules. Modules are files that you import elsewhere and provide certain functionality, but should generally not *do* much other than defining functions and classes. In scripts you can do whatever you like, naturally :)
You can make modules that you can also execute as a script. You can use `` if __name__ == ‘__main__’:`` to detect that its run as a script and then e.g. invoke any of the functions that it defines.
I hope this helps a bit.
> And more importantly, are there debug implications of these two different ways of executing code? On a related note - if I make changes to code, and then save and run "execute file" again, then debugging still seems coherent. Do I need to do both of these things after a code edit so that the debugger doesn't get confused.
There should not really be debug implications, except that code in a module is always associated with a module, whereas code being executed is not necessarily, but that’s why you should not execute selected or cell in code where there are breakpoints :)
If you re-execute a script in a running shell, everything gets updated fine. But modules, once imported, won’t re-import. You can force them to, but that can lead to nasty side effects. This is basically why IEP has “run as script”, which restarts the shell to ensure a clean sheet.
> Also, if you have any input on why I can't seem to get the %recall magic command to work with a line number, I'd love some help. I tried Spyder, and it behaves the same way.
That’s because the IPython shell in IEP is a bit of an odd mix of IEP and IPython. You’ve already encountered that it uses IEP’s debugging mechanism. Further, IEP takes care of the autocompletion (using a dropdown), and command history. Both of these functionalities in IPython are sort of ignored. I suspect that Spider has a similar cause.
> But it did make me curious. Suppose I want update a component in Pyzo, either the IPython version or the SciPy version. Is this easy or hard?
Easy. In the shell you can just do `conda update scipy` to get the latest. Pyzo is really just a pre-packaged conda distribution.
- Almar
> Thanks again!
>
> - Andy
On Wednesday, December 30, 2015 at 8:14:28 PM UTC-7, jandyman...@gmail.com wrote:
Hello,
Forgive my beginner mistakes, but I cannot seem to figure out how to get breakpoints to work. I can set them in the left margin and see a red filled circle next to the line I want to break at. However, when I call the function which has the breakpoint in it, the breakpoint is not hit, the function runs as if there is no breakpoint.
Background: I am a 40 year veteran programmer in scores of languages, but am a complete beginner in Python. I'm learning it so I can use SciPy as a Matlab alternative. So any setup that may be need to enable debugging is not something I will know anything about.
Thanks in advance for any help!
- Andy
--