What is the method of debugging in Python?
Apr 29, 2023 pm 09:01 PMTest code used in this article:
from torchvision import transforms from torchvision.datasets import FashionMNIST import os os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE" #數(shù)據(jù)集準(zhǔn)備 train_data = FashionMNIST( root = "./data/FashionMNIST", train = True, transform = transforms.ToTensor(), download = True #如果沒下載數(shù)據(jù),就下載數(shù)據(jù);如果已經(jīng)下載好,就換為False ) test_data = FashionMNIST( root = "./data/FashionMNIST", train = False, transform = transforms.ToTensor(), download = True #如果沒下載數(shù)據(jù),就下載數(shù)據(jù);如果已經(jīng)下載好,就換為False ) train_data_x=train_data.data train_data_y=train_data.targets test_data_x=test_data.data test_data_y=test_data.targets print(train_data_x.shape) print(train_data_y.shape) print(type(train_data_x)) print(type(train_data_y)) print(test_data_x.shape) print(test_data_y.shape) def function1(x): for i in range(x): print(i) function1(7)
1. Introduction to debug environment
Click this crawler to start debugging
in Before debugging, we need to set breakpoints: (Several settings will do)
After entering debug, the lower left corner:
1) You can see the existing variables in the debugger:
2) In the console, you can see the step-by-step debugging process, and the output results will be printed in it:
2. Introduction to the debug button
#1) step over shortcut key: F8
2) step into shortcut key: F7
3) step into my code shortcut key: alt shift F7
4) step out shortcut key: shift F8
2.1. step into: single-step execution (when encountering a function, it is also a single step)
Pay attention to the change of the blue line (the blue line means that it is about to be debugged, but it is still No debugging)
2.2. Step over: single-step execution (run all functions when encountering them)
Compared with step over, this is the difference between execution in the function: ( step over is executed directly)2.3, step into my code: (jump directly to the next breakpoint)
This is easy to understand. I have three breakpoints here, so I will debug three times and then end:
is the single-click function inside the function. When debugging step by step, use step out to complete the execution at once and return to the previous layer function.
After using it, the entire function is executed directly, but the process is not ended
Look at the blue line, returning to the previous layer of function
The above is the detailed content of What is the method of debugging in Python?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Use Seaborn's jointplot to quickly visualize the relationship and distribution between two variables; 2. The basic scatter plot is implemented by sns.jointplot(data=tips,x="total_bill",y="tip",kind="scatter"), the center is a scatter plot, and the histogram is displayed on the upper and lower and right sides; 3. Add regression lines and density information to a kind="reg", and combine marginal_kws to set the edge plot style; 4. When the data volume is large, it is recommended to use "hex"

String lists can be merged with join() method, such as ''.join(words) to get "HelloworldfromPython"; 2. Number lists must be converted to strings with map(str, numbers) or [str(x)forxinnumbers] before joining; 3. Any type list can be directly converted to strings with brackets and quotes, suitable for debugging; 4. Custom formats can be implemented by generator expressions combined with join(), such as '|'.join(f"[{item}]"foriteminitems) output"[a]|[

Install pyodbc: Use the pipinstallpyodbc command to install the library; 2. Connect SQLServer: Use the connection string containing DRIVER, SERVER, DATABASE, UID/PWD or Trusted_Connection through the pyodbc.connect() method, and support SQL authentication or Windows authentication respectively; 3. Check the installed driver: Run pyodbc.drivers() and filter the driver name containing 'SQLServer' to ensure that the correct driver name is used such as 'ODBCDriver17 for SQLServer'; 4. Key parameters of the connection string

pandas.melt() is used to convert wide format data into long format. The answer is to define new column names by specifying id_vars retain the identification column, value_vars select the column to be melted, var_name and value_name, 1.id_vars='Name' means that the Name column remains unchanged, 2.value_vars=['Math','English','Science'] specifies the column to be melted, 3.var_name='Subject' sets the new column name of the original column name, 4.value_name='Score' sets the new column name of the original value, and finally generates three columns including Name, Subject and Score.

Pythoncanbeoptimizedformemory-boundoperationsbyreducingoverheadthroughgenerators,efficientdatastructures,andmanagingobjectlifetimes.First,usegeneratorsinsteadofliststoprocesslargedatasetsoneitematatime,avoidingloadingeverythingintomemory.Second,choos

First, define a ContactForm form containing name, mailbox and message fields; 2. In the view, the form submission is processed by judging the POST request, and after verification is passed, cleaned_data is obtained and the response is returned, otherwise the empty form will be rendered; 3. In the template, use {{form.as_p}} to render the field and add {%csrf_token%} to prevent CSRF attacks; 4. Configure URL routing to point /contact/ to the contact_view view; use ModelForm to directly associate the model to achieve data storage. DjangoForms implements integrated processing of data verification, HTML rendering and error prompts, which is suitable for rapid development of safe form functions.

Introduction to Statistical Arbitrage Statistical Arbitrage is a trading method that captures price mismatch in the financial market based on mathematical models. Its core philosophy stems from mean regression, that is, asset prices may deviate from long-term trends in the short term, but will eventually return to their historical average. Traders use statistical methods to analyze the correlation between assets and look for portfolios that usually change synchronously. When the price relationship of these assets is abnormally deviated, arbitrage opportunities arise. In the cryptocurrency market, statistical arbitrage is particularly prevalent, mainly due to the inefficiency and drastic fluctuations of the market itself. Unlike traditional financial markets, cryptocurrencies operate around the clock and their prices are highly susceptible to breaking news, social media sentiment and technology upgrades. This constant price fluctuation frequently creates pricing bias and provides arbitrageurs with

iter() is used to obtain the iterator object, and next() is used to obtain the next element; 1. Use iterator() to convert iterable objects such as lists into iterators; 2. Call next() to obtain elements one by one, and trigger StopIteration exception when the elements are exhausted; 3. Use next(iterator, default) to avoid exceptions; 4. Custom iterators need to implement the __iter__() and __next__() methods to control iteration logic; using default values is a common way to safe traversal, and the entire mechanism is concise and practical.
