Server Side Programming Articles

Page 638 of 2109

How do I get time of a Python program\'s execution?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 24-Mar-2026 723 Views

Python provides different ways to measure the execution time of a script or specific code segments. The most common approaches use functions from the time module like time.time() and time.process_time(), or the dedicated timeit module for precise measurements. Here are the main methods to measure execution time in Python: Using time.time() Function Using time.process_time() Function Using timeit Module Using time.time() Function The time.time() function returns the current time as a floating-point number representing seconds since the Unix epoch (January 1, 1970). This ...

Read More

How to measure time with high-precision in Python?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 24-Mar-2026 5K+ Views

Python provides various modules, such as time, datetime, and timeit, to measure time with high accuracy. These modules offer high-resolution clocks to measure time intervals with precision needed for performance analysis and benchmarking. The following are several methods used to measure time with high precision in Python. Using time.time() Method Using time.perf_counter() Function Using timeit.default_timer() Using time.time() Method for Simple Timing The time.time() method returns the current time in seconds since the epoch as a floating-point number. The epoch is system-dependent, but ...

Read More

How to get min, seconds and milliseconds from datetime.now() in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 22K+ Views

Python's datetime module is used to extract various components of the current date and time, such as minutes, seconds, and even milliseconds. The datetime.now() method defined in the datetime module returns the current local date and time as a datetime object. This object allows us to access its individual components like minute, second, and microsecond. Using Attributes of datetime.now() to Extract Values Here we use the datetime.now() method to get the current minutes, seconds, and milliseconds. The now() function is defined under the datetime module. We retrieve the current minutes, seconds, and milliseconds by using .minute, .second, ...

Read More

How to convert unix timestamp string to readable date in Python?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 6K+ Views

You can use the fromtimestamp() function from the datetime module to convert a UNIX timestamp string to a readable date format. This function takes the timestamp as input and returns the datetime object corresponding to the timestamp. Converting Unix Timestamp to Readable Date Here's how to convert a Unix timestamp string to a readable date format ? import datetime # Convert timestamp string to readable date timestamp_str = "1500000000" timestamp = datetime.datetime.fromtimestamp(int(timestamp_str)) print(timestamp.strftime('%Y-%m-%d %H:%M:%S')) The output of the above code is ? 2017-07-14 08:10:00 Using Different Date Formats ...

Read More

How to subtract Python timedelta from date in Python?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 11K+ Views

The Python datetime module provides various ways for manipulating dates and times. One of its key features is the timedelta object, which represents duration and also the difference between two dates or times. Subtracting a specific amount of time from a date can be done using timedelta. For example, if we want to find the date a day before today, then we create a timedelta object with days=1 and then subtract it from the current date ? Subtracting One Day from Today's Date The basic use case is subtracting a single day from today's date. This can ...

Read More

How to convert Python date format to 10-digit date format for mysql?

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 2K+ Views

While working with databases like MySQL, it's necessary to store dates in a numeric format, especially for timestamps. MySQL commonly uses Unix timestamps, which are 10-digit numbers representing the number of seconds since January 1, 1970 (known as the epoch). The following are the different methods from the time and datetime modules to convert Python date formats into a 10-digit format (Unix timestamp) suitable for use with MySQL. Using mktime() Method The mktime() method from the Python time module is the inverse function of the localtime(). This method converts a time.struct_time object or a tuple with 9 ...

Read More

How to convert date to datetime in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 42K+ Views

In this article, we will discuss how to convert a date to a datetime object in Python. We use the combine() method from the Date & Time module to combine a date object and a time object into a single datetime object. While the date object represents only the calendar date (year, month, day), sometimes we need the full datetime object that includes time (hour, minute, second) as well. Following are several ways to achieve this ? Syntax The syntax of the combine() method is as follows ? datetime.combine(date, time) Using combine() with ...

Read More

Which one is more accurate in between time.clock() vs. time.time()?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 24-Mar-2026 750 Views

Two commonly used functions from the Python time module are time.time() and time.clock(). Each function provides a different purpose and returns different values depending on the platform (Windows vs. Unix). In Python 3.8, time.clock() was removed, so time.perf_counter() or time.process_time() are generally preferred over the older time.clock() for specific CPU time measurements. The time.clock() was designed for measuring process CPU time, while time.time() measures wall-clock time. time.time() is more accurate for measuring overall elapsed time (the duration of time that has passed between two specific points in time). Measuring Elapsed Time with time.time() The time.time() function ...

Read More

What are negated character classes that are used in Python regular expressions?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 24-Mar-2026 1K+ Views

While working with Python regex, if we want to match everything except certain characters, then we can use negated character classes by placing a caret (^) as the first character inside square brackets. The pattern [^abdfgh] will match any character not in that set. What is a Negated Character Class? A character class like [abc] matches any single character that is 'a', 'b', or 'c'. But if we use a ^ symbol at the beginning, like [^abc], it will match any character except 'a', 'b', or 'c'. This allows us to exclude certain characters from the match quickly. ...

Read More

What are metacharacters inside character classes used in Python regular expression?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 596 Views

Python's regular expressions provide various ways to search and manipulate strings. Metacharacters are special characters that carry specific meaning in regex patterns. However, their behavior changes significantly when used inside character classes (denoted by square brackets []). Understanding how metacharacters behave within character classes is crucial for writing accurate regular expressions. Most metacharacters lose their special meaning inside character classes, but some retain or alter their behavior. Understanding Character Classes Character classes are denoted by square brackets [] and define a set of characters that can match at a single position. For example, [aeiou] matches any single ...

Read More
Showing 6371–6380 of 21,090 articles
« Prev 1 636 637 638 639 640 2109 Next »
Advertisements