Home > Article > Backend Development > IPython 8.0 major version update supports code auto-completion
After more than 3 years of planning, IPython 8.0 is finally here.
Now, with the latest version, you can not only use Black to reformat the code in the command line, but also get a better automatic code completion and debugging experience.
For more details, let’s read on.
Optimization Error
Before version 8.0, if an error occurred in the code, IPython's error traceback would display a hash value used to compile the Python AST, like this:
#Now, the error traceback has been formatted correctly and can display the specific cell number where the bug is located.
In addition, IPython 8.0 also integrates stack_data. This package provides more intelligent tracking information, which can highlight the AST nodes where errors occur and help quickly locate bugs.
For example, for a piece of code like this:
If you call bar(), you will get an IndexError. IPython 8.0 will tell you where the index error occurs.
Note: In the terminal and notebook, the location marked with ^ will be highlighted.
Another improvement that has a greater impact on productivity is to add a colon and line number after the file name of the error traceback.
Many terminals and editors allow you to jump directly to the relevant file/line when using this syntax.
Automatic code completion suggestions
In addition to a better Debug experience, if you like the code automatic completion function in Ptpython, then now you can do it in IPython 8.0 It can also be used.
Accept these suggestions via ctrl-f, or ctrl-e, or by pressing the right arrow.
The alt-f shortcut key can only accept the first word of the suggestion.
Currently, auto-suggestions can only be displayed in emacs or vi mode.
Use "?" and "??" to view object information
In IPDB, you can now use "?" and "??" to display object information. The same goes for when using the IPython prompt:
Auto-formatting with black in the CLI
If black is installed with The same environment as IPython, so now, terminal IPython will by default reformat command line (CLI) code wherever possible.
Of course, you can also use —TerminalInteractiveShell.autoformatter=None to disable this option.
History Scope Global Features
Previously, when using %history, users could specify the session and row:
Or use global mode:
But before 8.0, these two modes cannot be used at the same time. If the user specifies both modes, IPython will apply the global mode (globalize all history) and ignore the specified scope.
This feature is now enhanced so that if the user specifies both a range and a glob pattern, the glob pattern will be applied to the specified historical range.
If you want to know more information, here is the official website link:
https://www.php.cn/link/003dd617c12d444ff9c80f717c3fa982
By the way, I would like to remind you that if you want to use IPython 8.0, you must first upgrade Python to version 3.8 or above.
The above is the detailed content of IPython 8.0 major version update supports code auto-completion. For more information, please follow other related articles on the PHP Chinese website!