Frage

I am using DataNitro to write Python Script in Excel. Its very useful indeed. However, when I open the Idle editor in excel, the accompanying Python Shell is not interactive, in that it does not return print statements, show errors, nothing. It just restarts every time I run the programme. This makes it incredibly hard to debug as I can't use print statements to trace the errors.

Does anyone know if this is a bug with DataNitro, or is it supposed to be that way, or whats going on? are there any solutions?

Thanks so much

War es hilfreich?

Lösung

Our IDLE editor is just an editor - it doesn't work as a shell.

The best way to debug programs is to raise an exception. This will freeze the shell that opens when a script is run, and you'll be able to inspect the variables and see any print statements that were generated during execution.

For example, if you run:

print Cell("A1").value
x = Cell("B1").value
raise

You'll see the value of A1 printed to the shell, and you can enter "x" at the prompt to see the value of B1.

You can also import a script you're working on into the regular Python shell (the one that opens when you press "shell"). This will execute the code in that script.

We'll be adding a guide to debugging code to the site soon, as well as some features that make it easier.

Source: I'm one of the founders of DataNitro.

Andere Tipps

Not as knowledgeable as Ben, but have been using DataNitro quite a bit and here are some tips:

The shell automatically closes once the script has run. If you want to inspect some prints or even interact with the shell I normally place following at end of my script.

raw_input("Press Enter to Exit shell")

Not very elegant, but I have even created a small loop that displays text options in the console. Can then interact with your program and sheet from there. Clever and more elegant way would be to have your script poll an excel cell and then take action form there.

Something else that you might find nice is that it also also you to run Ipython instead of the default python shell. Cannot imagine using python without Ipython... so you get benefits of tab completion Ipython debugging etc. To activate that just click the "Use Ipython" Checkbox in DataNitro Settings (don't know if this is version dependent).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top