In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what is the python time library". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what is the python time library.
Catalogue
The role of the 1.Time Library
2. The use of Time library
Time acquisition function
Time formatting: show time in a reasonable way
Construct a time in the form of a string
Program timing application: the process of measuring the time experienced by a start-stop action
3. Example: text progress bar
Example 1: each progress line break:
Example 2: each progress does not change the line, but constantly refreshes: overwrite the previous character with the printed character
Extension: different design functions of the text progress bar:
The role of the 1.Time Library
Time library is the standard library of processing time in Python.
Provides the function of getting system time and formatting output
Provide system-level accurate timing function for program performance analysis
2. The use of Time library
Let's clarify a few concepts:
Time stamp: the total number of seconds since 00: 00: 00 GMT, January 1, 1970 (08:00:00, Beijing time, January 1, 1970) is a number.
A common way to get time in Python is to get the timestamp first, and then convert it to the desired time format.
Tuple struct_time: date and time contain many variables, so a tuple struct_time is defined in Python to combine all these variables, including year, month, day, hour, minute, second, and so on.
Time acquisition function
Time formatting: show time in a reasonable way
Construct a time in the form of a string
Question: can we construct a time in the form of a string, such as "2018-01-26 12:55:20" and turn it into a time variable?
The answer is yes, by showing that the parameters defined by the template parse each corresponding value in the string one by one, it may form a time variable. Into a time that can be operated inside a computer.
Program timing application: the process of measuring the time experienced by a start-stop action
Question: the perf_counter () function is used for program timing, but isn't the time () function OK?
Answer:
Time () is relatively less precise, and affected by the system, it is suitable to represent the date and time or the timing of large programs.
Perf_counter () is suitable for smaller program tests and calculates the sleep () time.
3. Example: text progress bar example 1: each progress line wrap:
The print () function outputs one character by default and wraps it to the next line, so there is no need to do anything else.
Output result > >
Example 2: each progress does not change the line, but constantly refreshes: overwrite the previous character with the printed character
In order to achieve a single-line dynamic refresh, we need to require our program not to wrap to the next line when outputting a string of one character. Because after switching to the next line, the previous information cannot be modified.
Escape character\ r (move the cursor to the beginning of the line)
The use of escape characters bothered me for a long time, such as where to put it, so I put it in a separate document to introduce ~ ~
Output result > >
Extension: different design functions of the text progress bar:
Thank you for your reading, the above is the content of "what is the python time library", after the study of this article, I believe you have a deeper understanding of what is the python time library, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.