Python Articles

Page 799 of 855

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

Chandu yadav
Chandu yadav
Updated on 30-Jun-2020 968 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

Conversions between color systems using Python (colorsys)

George John
George John
Updated on 30-Jun-2020 441 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

Locating and executing Python modules (runpy)

Chandu yadav
Chandu yadav
Updated on 30-Jun-2020 4K+ 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

Determine type of sound file using Python (sndhdr)

George John
George John
Updated on 30-Jun-2020 317 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

Detection of ambiguous indentation in python

Arjun Thakur
Arjun Thakur
Updated on 30-Jun-2020 672 Views

Indentation is an important feature of Python syntax. Code blocks in function, class or loops are required to follow same indent level for statements in it. The tabnanny module in Python's standard library is able to detect any violation in this stipulation.This module is primarily intended to be used in command line mode with –m switch. However, it can also be imported in an interpreter session.Command line usagepython –m tabnanny –q example.pyFor verbose output use –v switchpython –m tabnanny –v example.pyFollowing functions are defined in tabnanny module for checking indentation programmatically.check()This function checks for ambiguously indented lines in a given ...

Read More

Sound-playing interface for Windows in Python (winsound)

George John
George John
Updated on 30-Jun-2020 4K+ Views

The winsound module is specific to Python installation on Windows operating system. The module defines following functions −Beep()When this function is called a beep is heard from the PC’s speaker. The function needs two parameters. The frequency parameter specifies frequency of the sound, and must be in the range 37 through 32, 767 hertz. The duration parameter specifies duration of sound in .>>> import winsound >>> winsound.Beep(1000, 500)MessageBeep()This function plays a sound as specified in the registry. The type argument specifies which sound to play. Possible values are −-1, MB_ICONASTERISK, MB_ICONEXCLAMATION, MB_ICONHAND, MB_ICONQUESTION, and MB_OK (default).The value -1 produces a ...

Read More

Defining Clean Up Actions in Python

Samual Sam
Samual Sam
Updated on 30-Jun-2020 1K+ Views

There are numerous situation occurs when we want our program to do this specific task, irrespective of whether it runs perfectly or thrown some error. Mostly to catch at any errors or exceptions, we use to try and except block.The “try” statement provides very useful optional clause which is meant for defining ‘clean-up actions’ that must be executed under any circumstances. For example −>>> try:    raise SyntaxError finally:    print("Learning Python!") Learning Python! Traceback (most recent call last):    File "", line 2, in       raise SyntaxError    File "", line None SyntaxError: The final clause ...

Read More

Performing Google Search using Python code?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jun-2020 1K+ Views

In this article, we will try to do google search using python code, this comes handy in case you are working on a python project and you need to access some data from the web and the search result(from the web) is going to be used inside your project.Prerequisite –You must have python installed on your system.Install google module. You can use pip to install google module like below −C:\Users\rajesh>python -m pip install google Collecting google Downloading https://files.pythonhosted.org/packages/c8/b1/887e715b39ea7d413a06565713c5ea0e3132156bd6fc2d8b165cee3e559c/google-2.0.1.tar.gz Requirement already satisfied: beautifulsoup4 in c:\python\python361\lib\site-packages (from google) (4.6.0) Installing collected packages: google Running setup.py install for google ... done Successfully installed ...

Read More

Plotting Google Map using gmplot package in Python?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jun-2020 4K+ Views

There are numerous ways you can draw geographical coordinates on Google Maps. However, in case you want to save it in a local file, one better way to accomplish is through a python module called gmplot.Python library gmplot allows us to plot data on google maps. gmplot has a matplotlib-like interface to generate the HTML and javascript to deliver all the additional data on top of Google Maps.InstallationIt is easy to install gmplot using pip incase gmplot is not already installed −pip install gmplotOn running above command, you may see output something like −From above, we can see the latest ...

Read More

Why importing star is a bad idea in python

Hafeezul Kareem
Hafeezul Kareem
Updated on 29-Jun-2020 566 Views

Importing all methods from a module in Python is a bad idea because of the following reasons.It is difficult to find a parent module of the method which we used in the programs.We are not allowed to create our functions with the names of methods.Let's see an example. Below we write a function called add in the sample.py.## sample.py file def add(a, b): return a + bExampleSave the above file in the same directory as below Python file.## let's assume we have module called sample from sample import * def add(*nums):    return sum(nums) print(add(1, 2, 3, 4, ...

Read More
Showing 7981–7990 of 8,547 articles
« Prev 1 797 798 799 800 801 855 Next »
Advertisements