0

This is my first post! :D

I am trying to learn how to use winpdb to debug some python code and have a problem. Consider the following python function, simple.py:

   def simple(a,b):

    c  = a + b

    return c 

I am in windows and using the command line in the directory where I have stored this function I attempt to run winpdb with the following command:

winpdb simple.py 2 1

Is this the correct way to debug the function simple.py with a = 2 and b = 1? As when I execute the above in the command line winpdb launches but with a and b undefined, for example (taken from the winpdb console when the above is entered into the cmd window):

> eval a
<type 'exceptions.NameError'>, name 'a' is not defined

I am sorry to have to ask such a basic question, but I can not seem to find any solutions online.

1 Answers1

0

The presented source file defines a function but it never calls the function and doesn't execute any code at all. Code in exactly that form can't be trivially debugged. Typically a sample call to function is added to the end of file, like

def simple(a, b):
    c = a + b
    return c
simple(1, 2)

Than you can start winpdb like

winpdb simple.py

place breakpoint in a function by clicking on margin of c = a + b line and press the Go button.

After that the program would stop in a state where you can use eval a and even eval simple(5, 6)

Vasily Galkin
  • 303
  • 5
  • 4