Found 10784 Articles for Python

Determine type of sound file using Python (sndhdr)

George John
Updated on 30-Jun-2020 09:28:38

199 Views

The sndhdr module in Python's standard library provides utility functions that read the type of sound data which is in a file. The functions return a namedtuple(), containing five attributesfiletypestring representing 'aifc', 'aiff', 'au', 'hcom', 'sndr', 'sndt', 'voc', 'wav', '8svx', 'sb', 'ub', or 'ul'.frameratethe sampling_rate will be either the actual value or 0 if unknown or difficult to decode.nchannelsnumber of channels or 0 if it cannot be determined or if the value is difficult to decodenframeseither the number of frames or -1.sampwidthbits_per_sample, will either be the sample size in bits or 'A' for A-LAW or 'U' for u-LAW.functions in sndhdr ... Read More

Locating and executing Python modules (runpy)

Chandu yadav
Updated on 30-Jun-2020 09:29:11

3K+ Views

The –m option of command line option searches for a given module and execute it as the __main__ module. This mechanism is internally supported by runpy module from Python's standard module that allows scripts to be located using the Python module namespace rather than the filesystem.This module defines two functionsrun_module()This function executes the code of the specified module and return the resulting module globals dictionary.The mod_name argument should be an absolute module name. If the module name refers to a package rather than a normal module, then that package is imported and the __main__ submodule within that package is then ... Read More

The implementation of import in Python (importlib)

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

2K+ Views

The importlib package provides the implementation of the import statement in Python source code portable to any Python interpreter. This also provides an implementation which is easier to comprehend than one implemented in a programming language other than Python.This package also exposes components to implement import, making it easier for users to create their own custom objects (known as an importer) to participate in the import process.The importlib package has an important function named as import_module()import_module():This function imports a module programmatically. Name of module is first parameter to the function. Optional second parameter specifies package name if any.invalidate_caches():This function invalidates ... Read More

Conversions between color systems using Python (colorsys)

George John
Updated on 30-Jun-2020 09:30:03

254 Views

The RGB color model, named so because of the initials of the three additive primary colors, is an additive color model in which red, green and blue light are added to reproduce various colors.The RGB color model is used in representation and display of images in electronic systems, such as televisions and computers. It is based on human perception of colors. Other alternative representations of color model are:YIQ: Luminance, Chrominance (used by composite video signals)HLS: Hue, Luminance, SaturationHSV: Hue, Saturation, ValueThe colorsys module defines functions for conversion of color values between RGB color model and three other coordinate systems. In ... Read More

Read and write AIFF and AIFC files using Python (aifc)

Chandu yadav
Updated on 30-Jun-2020 09:30:50

540 Views

Various functions in aifc module provide support for reading and writing AIFF (Audio Interchange File Format) and AIFF-C files. AIFF format is for storing digital audio samples in a file. Its newer version AIFF-C has the ability to compress the audio dataAudio file has number of parameters describing the audio data.The sampling rate or frame rate: number of times per second the sound is sampled.The number of channels: indicate if the audio is mono, stereo, or quadro.frame : consists of one sample per channel.The sample size: size in bytes of each sample.Thus a frame consists of channels * samplesize bytes. ... Read More

Socket Programming with Multi-threading in Python?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

4K+ Views

Multithreading ConceptsMultithreading is the core concept of nearly all modern programming languages especially python because of its simplistic implementation of threads.A thread is a sub-program within a program that can be executed independently of other section of the code. A thread executes in the same context sharing program’s runnable resources like memory.When in a single process, we are executing multiple threads simultaneously, it is called multithreading.Python Multithreading Modules for a thread implementationTo implements threads in programs, python provides two modules −thread (for python 2.x) or _thread(for python 3.x) modulethreading moduleWhere the thread module creates a thread as a function whereas ... Read More

Barrier Objects in Python

Samual Sam
Updated on 30-Jul-2019 22:30:24

382 Views

Barrier provides one of the python synchronization technique with which single or multiple threads wait until a point in a set of activities and make progress together.To define a barrier object, “threading. Barrier” is used.threading.Barrier(parties, action = None, timeout = None)Where, parties = Number of threadsaction = called by one of the threads when they are released.timeout = Default timeout value. In case no timeout value is specified for the wait(), this timeout value is used.Below mentioned methods are used by Barrier class.Sr.NoMethod & Description1partiesA number of threads required to reach the common barrier point.2n_waitingNumber of threads waiting in the ... Read More

Python library PyTube to download youtube videos

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

401 Views

You know “youtube” right? Yes that most famous video sharing website especially in india . Most of the time, you like some videos and you try to download that video so as to check it later/offline. Then you come across “youtube-downloader” app to download youtube videos from the youtube website. But most of the apps comes with some restriction (if you are using it for free) or cost you money. But have you ever think of creating our own program to download youtube videos? If not you, then you should try as its very simply to do using the python ... Read More

Keyed-Hashing for Message Authentication in python

Samual Sam
Updated on 30-Jul-2019 22:30:24

617 Views

Message authentication using cryptographic hash functions in python can be achieved through the HMAC mechanism. We can use HMAC with multiple iterable hash functions such as MD5, SHA-1 in combination with a secret shared key.The basic idea is to secure our data, by generating a cryptographic hash of the actual data combined with a shared secret key. The final result is sent without the secret key but the resulting hash can be used to check the transmitted or stored message.Syntaxhmac.new(key, msg = None, digestmod = None)Returns a generate new hmac object.Where −Key – The shared secret key here.Msg – the ... Read More

Website Blocker Using Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

1K+ Views

If you are working in a big IT company then you may notice that their couple of websites are blocked especially social networking sites like facebook, youtube, Instagram etc.Instead of using third-party applications to blocks certain website, we can develop our own custom application which will block websites of our choice and developing a website blocker in python is not so difficult too. That’s what we going to do- develop a python script which will block the website we want.Prerequisite:Python 3.x installedBasic knowledge of PythonWhat we are going to do:We are going to develop python application which will block a ... Read More

Advertisements