Loading video player…

Type More Quickly and Accurately

00:00 Type More Quickly and Accurately. When using the regular Python REPL, your coding speed is directly limited by how quickly you can type and how well you remember the names of functions, arguments, and so on.

00:16 bpython provides useful suggestions that you can apply at the press of a button with auto-completion. In addition, it helps you correctly indent your code and offers contextual history.

00:27 All these features can save you a lot of typing and help avoid annoying typos, making you faster and more productive at work. As soon as you start typing something, byython will look up Python keywords, built-ins, globals, and your current lexical scope according to the LEGB rule to find objects with matching names.

00:48 It matches names that begin with a specific sequence of characters, so typing more characters will narrow down the results. It will then display a list of relevant suggestions in alphabetical order.

01:03 In this example, you are getting suggestions for the pass statement, a few built-in functions such as print(), and two user-defined variables called program and program_scope that were defined earlier in the current global scope.

01:16 You can cycle forward through these suggestions with Tab or backwards with Shift + Tab. This can be especially helpful when there’s too much content to fit on your screen.

01:29 Code suggestions also work in other places, a handy feature that you may use for type introspection to find out what attributes and methods are available in an object,

01:44 but that’s not all. Code suggestions go hand in hand with auto-completion, which is another useful feature in many editors, including bpython. Essentially, it can write the remaining code for you when there’s no ambiguity about what you’re trying to type. In this example, the correct variable, program, has been selected and can be completed by hitting Enter.

02:09 As you cycle through the available suggestions with Tab or Shift + Tab, Python goes ahead and inserts the highlighted option into the Python REPL.

02:20 On the other hand, if there’s only one suggestion left and you haven’t finished typing the whole name, then you can press Tab to have Python automatically complete the remaining part as seen here with print(), which can then be completed by typing in the normal way.

02:36 A lesser-known fact about Python’s auto-completion mechanism is that it understands your file system. In other words, when you start typing a string literal that resembles a file path and you hit Tab, Python will list all the files and folders that match the string that you’ve typed so far.

03:07 In the next section of the course, you’ll see more ways that Python can help you type more quickly and accurately.

Become a Member to join the conversation.