Found 34494 Articles for Programming

Python Basic date and time types

George John
Updated on 30-Jul-2019 22:30:23

6K+ Views

To manipulate dates and times in the python there is a module called datetime. There are two types of date and time objects. The types are naïve and the aware. In the naïve object, there is no enough information to unambiguously locate this object from other date-time objects. In this approach it uses Coordinate Universal Time (UTC). In the aware type objects there are different information regarding algorithmic and political time adjustments. This type of objects is used to represent some specific time moments. To use this module, we should import it using − import datetime There are ... Read More

Python Completion function for GNU readline

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

269 Views

Unix readline module has tab completion mechanism. To get these features, we have to use rlcompleter module. It can be used in python’s interactive mode. To use this module, we should import it using − import rlcompleter There is a class called Completer class − Method Completer.complete(text, state) This method is used to return the tab completion output. If there is a ‘.’ in the text, then it will try to get all related members of that command. When there is no dot ‘.’ it will just complete the text. Example Code import rlcompleter import sys ... Read More

Python Helpers for Computing Deltas

AmitDiwan
Updated on 11-Aug-2022 11:02:59

177 Views

The difflib module is used in Python to compute deltas. It is used to compare files, and can produce information about file differences in various formats, including HTML and context and unified diffs. We need to first import the difflib module before using it − import difflib Class (difflib.SequenceMatcher) This class is used to compare two sequences of any type. It has different methods. Some of the methods − set_seqs(a, b) − Set the sequence files which will be compared. It computes and caches detailed information about the second file. So for matching multiple files, we should set ... Read More

Python GNU readline Interface

Chandu yadav
Updated on 30-Jul-2019 22:30:23

619 Views

The readline is UNIX specific module. It defines a number of functions to read and write history files in easier way from python interpreter. We can use this module directly or using the rlcompleter module. This module settings may affect the built-in input() method prompt and also the interactive prompt. For the MAC based system (on MAC OS X) this readline module can be implemented using the libedit library. The libedit configuration is different from GNU readline. To use this module, we need to import the readline module in the python code import readline Some methods of ... Read More

Python Internet String Preparation

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

235 Views

To identify different things in the internet, it is necessary to compare different identification for equality. The comparison procedure depends on the application domain. For an example, some things are case-insensitive etc. To check these kind of information stringprep is used. The RFC 3454 defines the procedure to prepare the Unicode strings before transmitting through the wire. After going through the preparation procedure, they have a certain normalized form. The RFC defines a set of tables; these tables can be combined into profiles. For an example there is a profile of stringprep is nameprep. In the nameprep, there are internationalized ... Read More

Python Unicode Database

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

328 Views

The unicodedata module is used to access all of the Unicode characters using Unicode character databases. In this database, there are character properties of all characters. To use this modules, we need to import the unicodedata module in our code. import unicodedata Unicode Database Methods Some modules of the unicodedata module are described here. Module (unicodedata.lookup(name)) − This method is used to lookup the characters by name. When the name is valid, it should return the character. Otherwise it will raise the KeyError. Module (unicodedata.name(chr[, default]))− This method is used to return the name of the given ... Read More

Python Text Wrapping and Filling

George John
Updated on 30-Jul-2019 22:30:23

5K+ Views

In python the textwrap module is used to format and wrap plain texts. There are some options to format the texts by adjusting the line breaks in the input paragraph. To use these modules, we need to import the textwrap module in our code. import textwrap The Textwrapper instance attributes of the constructors are as follows − Sr.No. Attribute & Description 1 width The maximum length of lines. Default value is 70 2 expand_tabs If the value of this attribute is true, then all tabs will be replaced by spaces. Default value ... Read More

String Operations in Python

Chandu yadav
Updated on 25-Jun-2020 13:48:21

617 Views

In python, there is a standard library, called string. In the string module, there are different string related constants, methods, classes are available.To use these modules, we need to import the string module in our code.import stringSome string constants and their corresponding values are as follows −Sr.No.String Constant & Values into it1string.ascii_lowercase‘abcdefghijklmnopqrstuvwxyz’2string.ascii_uppercase‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’3string.ascii_lettersConcatenation of asci_lowwecase and ascii_uppercase ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’4string.digits‘0123456789’5string.hexdigits‘0123456789abcdefABCDEF’6string.octdigits‘01234567’7string.punctuation‘!"#$%&\'()*+, -./:;?@[\]^_`{|}~’8string.printableAll printable ASCII characters. It is collection of asci_letters, punctuation, digits and whitespace.‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+, -./:;?@[\]^_`{|}~ \t\r\x0b\x0c’9string.whitespace‘\t\r\x0b\x0c’Example Code Live Demoimport string print(string.hexdigits) print(string.ascii_uppercase) print(string.printable)Output0123456789abcdefABCDEF ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+, -./:;?@[\]^_`{|}~String FormattingThe built-in string class in python supports different complex variable substitution and value formatting by the format() method.To format ... Read More

Concrete Exceptions in Python

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

2K+ Views

There are some common exceptions in python. These exceptions are usually raised in different programs. These may raise by the programmer explicitly, or the python interpreter can raise these type of exceptions implicitly. Some of these exceptions are − Exception AssertionError The AssertionError may raise, when an assert statement fails. In python there are some, we can also set some assert statement in our code. The assert statement always must be true. if the condition fails, it will raise AssertionError. Example Code class MyClass: def __init__(self, x): self.x = ... Read More

Python Exception Base Classes

Ankith Reddy
Updated on 25-Jun-2020 13:51:15

5K+ Views

Like other high-level languages, there are some exceptions in python also. When a problem occurs, it raises an exception. There are different kind of exceptions like ZeroDivisionError, AssertionError etc. All exception classes are derived from the BaseException class.The code can run built in exceptions, or we can also raise these exceptions in the code. User can derive their own exception from the Exception class, or from any other child class of Exception class.The BaseException is the base class of all other exceptions. User defined classes cannot be directly derived from this class, to derive user defied class, we need to ... Read More

Advertisements