This site is from a past semester! The current version will be here when the new semester starts.

Appendix B: Using an IDE

There are several Python IDEs (Integrated Development Environments) that you can use to manage a Python programming project.

If you have not done so already, install Python in your Computer.

The standard Python installation comes with a basic IDE called IDLE. It can be used to write, run, and debug Python code.

PyCharm is a more sophisticated IDE that is widely used. PyCharm has a free community edition. The professional edition too is free for students.

Installing and setting up PyCharm


PyCharm's own documentation on setting up your first project in PyCharm is given here.

Exercise: Setup a Project in PyCharm

Exercise : Setup a Project in PyCharm

  1. Install Python and PyCharm if you haven't done so already.
  2. Start PyCharm and click on the Create New Project option.
  3. In the next screen, specify that as the project location.
  4. You can accept defaults for the remaining steps.
  5. To add a new file, right-click on project name and choose NewPython File. Provide a file name in the next screen. E.g., greet.py
  6. Type your code in the file.

    Here is an example:
    greeting = 'hello'
    
    
    def print_greeting(name):
        message = greeting + ' ' + name
        print(message)
    
    
    print_greeting('john')
    print_greeting('jane')
    
  7. To run the code, Right-click on project name and choose Run 'filename'.
  8. The output will appear in the panel at the bottom of the IDE.

Debugging in PyCharm


PyCharm's own documentation on debugging code in PyCharm is given here.

Exercise: Debug a Project in PyCharm

Exercise : Debug a Project in PyCharm

  1. Open a project in PyCharm. Go to a project file containing Python code.
  2. To create a breakpoint at a statement, click on the next to the line. A red dot should appear to indicate that the breakpoint has been set. You can remove the breakpoint by clicking on the red dot again.
  3. To start debugging, choose Debug instead of Run.
  4. The execution will pause at the first breakpoint. Use the debugging buttons to step through the code. You can see the , choose Debug instead of Run. You can see the value of the variables in the debugger Window, in the area below the debugging buttons.

    Useful buttons:
    • Step over: executes the statement and moves to the next statement
    • Step in: goes into the function that is called in the current statement.
    • Step out: finish executing the current function and goes back to the code that called the function.