Found 10476 Articles for Python

Generate Secure Random Numbers for Managing Secrets using Python

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

396 Views

To generate secure random numbers cryptographically we can use the secrets module in python. This module is helpful to create secure password, account authentication, security tokens or some related secrets. To use the classes and modules of the secrets module, we should import that module into our code. import secrets Random Numbers The secrets module is used to access some secure source of randomness. That is provided by the operating systems. Classes and functions, related to random numbers of the secrets modules are − Class secrets.SystemRandom It is a class to generate random numbers, by using some highest ... Read More

Secure Hashes and Message Digest in Python

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

2K+ Views

For the secure hash and message digest process, we should use the hashlib module. This module implements a common interface for different secure hash algorithm like SHA1, SHA224, SHA256, SHA512 etc. Also the RSA’s MD5 algorithm. Older algorithms are known as the Message Digest and the new methods are called Secure Hash. To use this module, we need to import the hashlib module in the python code. import hashlib In this method, there are some predefined algorithms like md5, sha1, sha224, sha256, sha512 are present. We can add additional algorithms from the OpenSSL library. Some methods, constants of ... Read More

Python Container Datatypes

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

2K+ Views

In the collections there are some container datatypes, which are alternatives to python’s general purpose built-in containers like dict, list, set etc.Some of the containers are −Sr.No.Container & Description1namedtuple()Used to create tuple subclass with the name field2dequeQueue using list type data3CounterSubclass of dict to count the hash-table objects4ChainMapUsed to create single view of multiple mappings5OrderedDictSubclass of dict, where data are added in ordered manner6UserListWrapper for list to easier access.To use this module, we should import it using −import collectionsDeque ObjectThe Deque is basically a generalization of stack and queue structure, where it is initialized from left to right. It uses ... Read More

Python Basic date and time types

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

7K+ 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 Helpers for Computing Deltas

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

259 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

855 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 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

Python Context Manager Types

Chandu yadav
Updated on 25-Jun-2020 13:51:46

250 Views

In python, the runtime context is supported by the with statement. The context is defined by the context manager. Using the context manager, we can create user defined classes to define the runtime context. It enters into the task before executing the statement body, and when the statement body is completed, it ends.There are two different methods for context manager. These methods are −Method __enter__()The __enter__() method is used to enter into the runtime context. It will return either the current object or another related object. The returned value is bound to the identifier in as clause of the with ... Read More

Python Binary Sequence Types

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

4K+ Views

The byte and bytearrays are used to manipulate binary data in python. These bytes and bytearrys are supported by buffer protocol, named memoryview. The memoryview can access the memory of other binary object without copying the actual data. The byte literals can be formed by these options. b‘This is bytea with single quote’ b“Another set of bytes with double quotes” b‘’’Bytes using three single quotes’’’ or b“””Bytes using three double quotes””” Some of the methods related to byte and bytearrays are − Method fromhex(string) The fromhex() method returns byte object. It takes a string where each byte is ... Read More

Python Sequence Types

SaiKrishna Tavva
Updated on 18-Dec-2024 19:22:23

10K+ Views

In Python programming, some basic sequence type classes are, Lists , Strings , Tuples, Range, etc, these data structures hold an ordered collection of items. They allow us to access their elements through indexing and iteration, there are additional sequence-type objects such as Byte sequences. Sequence Types In Python Sequence types in Python are categorized into two types they are mutable and immutable sequences. Mutable Sequence Types These Sequences can be changed after their creation, and also we can modify elements, adding new elements and removing existing ones. Lists: A list is a mutable, ordered ... Read More

Advertisements