Rajendra Dharmkar has Published 453 Articles

How does nested character class subtraction work in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Jul-2019 22:30:21

290 Views

Nested Character Class SubtractionSince we can use the full character class syntax within the subtracted character class, we can subtract a class from the class being subtracted. [0-9-[0-7-[0-3]]] first subtracts 0-3 from 0-7, yielding [0-9-[4-7]], or [0-38-9], which matches any character in the string 012389.The class subtraction is always the ... Read More

What are repeating character classes used in Python regular expression?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Jul-2019 22:30:21

406 Views

A character class followed by operators like '?', '*' or '+' are called repeating character classes.If you repeat a character class by using the '?', '*' or '+' operators, you will repeat the entire character class, and not just the character that it matched. The regex '[0-9]+' can match '579' ... Read More

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

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Jul-2019 22:30:21

842 Views

We come across negated character classes in Python regular expressions. An regex of ‘[abdfgh]’ matches any single character which is one of ‘a’, ‘b’, ‘d’, ’f’, ’g’ or ‘h’. This is termed a character class.An regex of ‘[^abdfgh]’ will match any single character which is NOT one of ‘a’, ‘b’, ‘d’, ... Read More

What Content-type is required to write Python CGI program?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Jul-2019 22:30:21

247 Views

If we run simple scripts like hello.py, its output is written on the STDOUT file, i.e., screen. There is one important and extra feature available which is the first line to be printed Content-type:text/html\r\r. This line is sent back to the browser and it specifies the content type to be displayed ... Read More

How do cookies work in Python CGI Programming?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Jul-2019 22:30:21

378 Views

Using Cookies in CGIHTTP protocol is a stateless protocol. For a commercial website, it is required to maintain session information among different pages. For example, one user registration ends after completing many pages. How to maintain user's session information across all the web pages?In many situations, using cookies is the ... Read More

What is the difference between time.clock() and time.time()?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Jul-2019 22:30:21

405 Views

The function time.time() returns the time in seconds since the epoch, i.e., the point where the time starts.For Unix, the epoch is January 1, 1970. For Windows, the epoch is January 1, 1601.time.time() is used for benchmarking on Windows. time.time() behaves the same on both UNIX and Windows but time.clock() ... Read More

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

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Jul-2019 22:30:21

274 Views

Use time.clock() for timing/benchmarking if you need to choose between time and clock in Python.time() returns the the seconds since the epoch, in UTC, as a floating point number on all platforms. On Unix time.clock() measures the amount of CPU time that has been used by the current process, so ... Read More

Why do I get different timestamps in python on different machines?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Jul-2019 22:30:21

127 Views

An timestamp is an offset value between a point in time line and the epoch, it's nothing to do with timezone. When it's converted to a human readable string like '%Y-%m-%d %H:%M:%S' that doesn't include any timezone information, python assumes that you want to use local timezone setting.datetime.timestamp() on a ... Read More

How does the destructor method __del__() work in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Jul-2019 22:30:21

482 Views

The __del__() method is a known as a destructor method. It is called when an object is garbage collected which happens after all references to the object have been deleted.In a simple case this could be right after you delete a variable like del x or, if x is a ... Read More

Can Python functions run in html as javascript does?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Jul-2019 22:30:20

158 Views

It is not possible to run Python in any modern browser because none contain a python interpreter. Javascript is the only language which runs in a browser without plugins like Flash or ActiveX.One way to write Python code that will run in the browser is to use a "transpiler". This ... Read More

Advertisements