In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use the IPython8.0 command-line interaction tool. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Foreword:
IPython is an enhanced version of Python's native interactive shell that can accomplish many unusual tasks, such as helping with parallel computing, and mainly using the interactive help it provides, such as code coloring, improved command-line callbacks, tab completion, macro capabilities, and improved interactive help.
IPython 8.0 has been brewing for a long time, mainly improving the existing code base and several new features. New features include reformatting code using Black in CLI, ghost advice, and better backtracking of highlighted error nodes, making complex expressions easier to debug.
1. Retroactive improvement
The previous error backtracking shows a hash table (hash) for compiling Python AST:
In [1]: def foo ():...: return 3 / 0...:In [2]: foo ()-ZeroDivisionError Traceback (most recent call last) in-> 1 foo () in foo () 1 def foo ():-> 2 return 3 / 0 3ZeroDivisionError: division by zero
Now that the error backtracking is in the correct format, the cell number in which the error occurred is displayed:
In [1]: def foo ():...: return 3 / 0...:Input In [2]: foo ()-ZeroDivisionError Traceback (most recent call last) input In [2] In-> 1 foo () Input In [1], in foo () 1 def foo ():-> 2 return 3 / 0ZeroDivisionError: division by zero
The second backtracking improvement is the integration of the stack_data package; it provides smarter information in the backtracking; it highlights the AST node where the error occurred, which helps to quickly narrow the error range, such as:
Def foo (I): X = [0] return x [0] [I] [0] def bar (): return foo (0) + foo (1) + foo (2)
Calling bar () raises a foo,IPython 8.0 on the return line of IndexError to tell you where the index error occurred:
IndexErrorInput In [2], in-> 1 bar () ^ Input In [1], in bar () 6 def bar ():-- > 7 return foo (0) + foo (^ ^ 8 1 ^ 9) + foo (2) ^ Input In [1] In foo (I) 1 def foo (I): 2 x = [0]-> 3 return x [0] [I] [0] ^
The location marked with ^ is highlighted on the terminal.
The third backtracking improvement is the most cautious, but has a big impact on productivity by appending a colon:: and line number to the filename in the backtracking:
ZeroDivisionError Traceback (most recent call last) File ~ / error.py:4, in 1 def f (): 21 Maximus-> 4 f () File ~ / error.py:2, in f () 1 def f ():-> 21 Universe 0
The integration capabilities of many terminals and editors allow you to jump directly to the file / line related to the error when using this syntax.
two。 Automatic suggestion
Ptpython allows users to enable automatic recommendations in ptpython/config.py, which contains rich code completion recommendations
As shown in the figure:
Currently, it is automatically recommended to display only in emacs or vi insert edit mode:
The ctrl e, ctrl f, and alt f shortcuts work in emacs mode by default.
To use these shortcuts in vi insert mode, you must create a custom key binding in config.py.
3. Use "?" And "?" View object information
In IPDB, you can now use "?" And "?" To display information about the object, as can be done when using the IPython prompt:
Ipdb > partial?Init signature: partial (self, /, * args, * * kwargs) Docstring:partial (func, * args, * * keywords)-new function with partial applicationof the given arguments and keywords.File: ~ / .pyenv/versions/3.8.6/lib/python3.8/functools.pyType: typeSubclasses:4. Historical scope global function
Previously, when using the% history feature, the user could specify the scope of the session and line, for example:
5 # see history from the first line of 8 sessions ago, # to the fifth line of 6 sessions ago.``
Or you can specify the global mode (global):
-g # glob ALL history for the specified pattern.
However, you cannot specify both, and if the user does specify scope and global mode, the glob mode (with all histories) will be used and the scope will be ignored.
Now this feature has been enhanced, and if the user specifies both the scope and the glob mode, the glob mode will be applied to the specified historical range.
Thank you for reading! This is the end of this article on "how to use IPython8.0 Command Line Interactive tools". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.