dpkg -i wingide5_5.0.9-1_i386.deb

dpkg -i wingide5_5.0.9-1_i386.deb
This should install WingIDE as planned. If you get any installation errors, there might be unmet
dependencies. In this case, simply run:
root@kali:~#
apt-get -f install
This should fix any missing dependencies and install WingIDE. To verify that you’ve installed it
properly, make sure you can access it as shown in
Figure 1-2
.
Figure 1-2. Accessing WingIDE from the Kali desktop
Fire up WingIDE and open a new, blank Python file. Then follow along as I give you a quick rundown
of some useful features. For starters, your screen should look like
Figure 1-3
, with your main code
editing area in the top left and a set of tabs on the bottom.
Figure 1-3. Main WingIDE window layout
Let’s write some simple code to illustrate some of the useful functions of WingIDE, including the
Debug Probe and Stack Data tabs. Punch the following code into the editor:
def sum(number_one,number_two):
number_one_int = convert_integer(number_one)
number_two_int = convert_integer(number_two)
result = number_one_int + number_two_int
return result
def convert_integer(number_string):
converted_integer = int(number_string)
return converted_integer
answer = sum("1","2")
This is a very contrived example, but it is an excellent demonstration of how to make your life easy
with WingIDE. Save it with any filename you want, click the Debug menu item, and select the Select
Current as Main Debug File option, as shown in
Figure 1-4
.
Figure 1-4. Setting the current Python script for debugging
Now set a breakpoint on the line of code that says:
return converted_integer
You can do this by clicking in the left margin or by hitting the F9 key. You should see a little red dot
appear in the margin. Now run the script by pressing F5, and execution should halt at your breakpoint.
Click the Stack Data tab and you should see a screen like the one in
Figure 1-5
.
The Stack Data tab is going to show us some useful information such as the state of any local and
global variables at the moment that our breakpoint was hit. This allows you to debug more advanced
code where you need to inspect variables during execution to track down bugs. If you click the drop-
down bar, you can also see the current call stack, which tells you which function called the function
you are currently inside. Have a look at
Figure 1-6
to see the stack trace.
Figure 1-5. Viewing stack data after a breakpoint hit
Figure 1-6. Viewing the current stack trace
We can see that
convert_integer
was called from the
sum
function on line 3 of our Python script.
This becomes very useful if you have recursive function calls or a function that is called from many
potential places. Using the Stack Data tab will come in very handy in your Python developing career!
The next major feature is the Debug Probe tab. This tab enables you to drop into a Python shell that is
executing within the current context of the exact moment your breakpoint was hit. This lets you inspect
and modify variables, as well as write little snippets of test code to try out new ideas or to
troubleshoot.
Figure 1-7
demonstrates how to inspect the
converted_integer
variable and change
its value.
Figure 1-7. Using Debug Probe to inspect and modify local variables
After you make some modifications, you can resume execution of the script by pressing F5.
Even though this is a very simple example, it demonstrates some of the most useful features of
WingIDE for developing and debugging Python scripts.
[
4
]
That’s all we need in order to begin developing code for the rest of this book. Don’t forget about
making virtual machines ready as target machines for the Windows-specific chapters, but of course
using native hardware should not present any issues.
Now let’s get into some actual fun!
[
1
] You can download VMWare Player from
http://www.vmware.com/
.
[
2
] For a “clickable” list of the links in this chapter, visit
http://nostarch.com/blackhatpython/
.
[
3
] For a comparison of features among versions, visit
https://wingware.com/wingide/features/
.
[
4
] If you already use an IDE that has comparable features to WingIDE, please send me an email or a tweet because I would love to
hear about it!
|