Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways for pycharm to check the value of a variable

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "what are the methods of pycharm to check the value of variables?" in the operation of actual cases, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Method 1: insert breakpoint and run Debug

Before the statement that you want to see the value of the variable, insert a breakpoint and Debug runs. After that, under the Debug panel, you can view the values of each variable, and then press F8, F7, and F9 to view and debug the code. You can also right-click on some variables and select "Add to Watches" for special monitoring; for Array, you can right-click and select View as array to view the data in the form of a table.

Method 2: check Run with Python console

1. In the menu bar, select Edit Configuration from the drop-down menu of the project.

2. Check Run with Python console in the settings of the corresponding project (here is the new version, but in the old version, this option is changed to "Show command line afterwards")

3. After running the program, click the glasses button in the console to view the value of the variable.

Method 3: use run in the current console

When running a python program, instead of using run in the menu bar, type: run your python file name under the current debug to run small debug scripts, such as visualization of a few variables, you can use: run-I your python file name

-I means: the source file runs in the current IPython namespace rather than in a new namespace, that is, as a script like MATLAB. At this point, you can directly call the variables in workspace.

Method 4: you can view it with print output.

It seems rubbish, but in fact, this method is the preferred method in many cases.

Add: other minor problems

1. Pay attention to the distinction between Python Console (console) and Terminal (terminal) in Pycharm

2. There may be conflicts between the system's python environment and ipython.

1. You can uninstall the current version of ipython and the next lower version of ipython

Check the version of ipython. I am currently the latest version 7.8.0.

Pip show ipython

Uninstall the current version:

Pip uninstall ipython

Install version 6.2.0

Pip install ipython==6.2.0

Finally, remember to restart Pycharm!

Or check the box of user IPython if available below.

This is the end of the content of "what are the ways for pycharm to check the value of variables". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report