Found 10805 Articles for Python

Generate and parse Mac OS X .plist files using Python (plistlib)

Smita Kapse
Updated on 30-Jul-2019 22:30:25

1K+ Views

Files with '.plist' the extension is used by Mac OS X applications to store application properties. The plislib module provides an interface to read/write operations of these property list files.The plist file format serializes basic object types, like dictionaries, lists, numbers, and strings. Usually, the top level object is a dictionary. To write out and to parse a plist file, use the dump() and load() functions. Serialized byte strings are handled by use dumps() and loads() functions. Values can be strings, integers, floats, booleans, tuples, lists, dictionaries (but only with string keys).This module defines the following functions −load()Read a plist ... Read More

Inspect live objects in Python

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

514 Views

Functions in this module provide usefule information about live objects such as modules, classes, methods, functions, code objects etc. These functions perform type checking, retrieve source code, inspect classes and functions, and examine the interpreter stack.getmembers()− This function returns all the members of an object in a list of name, value pairs sorted by name. If the optional predicate is supplied, only members for which the predicate returns a true value are included. getmodulename() −This function returns the name of the module named by the file path, without including the names of enclosing packagesWe shall be using following script for ... Read More

Filtering Images based on size attributes in Python?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

189 Views

Python provides multiple libraries for image processing including Pillow, Python Imaging library, scikit-image or OpenCV.We are going to use Pillow library for image processing here as it offers multiple standard procedures for image manipulation and supports the range of image file formats such as jpeg, png, gif, tiff, bmp and others.Pillow library is built on top of Python Imaging Library(PIL) and provides more features than its parent library(PIL).InstallationWe can install pillow using pip, so just type following in the command terminal −$ pip install pillowBasic operation on a pillowLet’s some basic operation on images using pillow library.from PIL import Image ... Read More

Configuration file parser in Python (configparser)

Anvi Jain
Updated on 30-Jul-2019 22:30:25

12K+ Views

The configparser module from Python's standard library defines functionality for reading and writing configuration files as used by Microsoft Windows OS. Such files usually have .INI extension.The INI file consists of sections, each led by a [section] header. Between square brackets, we can put the section’s name. Section is followed by key/value entries separated by = or : character. It may include comments, prefixed by # or ; symbol. A sample INI file is shown below −[Settings] # Set detailed log for additional debugging info DetailedLog=1 RunStatus=1 StatusPort=6090 StatusRefresh=10 Archive=1 # Sets the location of the MV_FTP log file LogFile=/opt/ecs/mvuser/MV_IPTel/log/MV_IPTel.log ... Read More

Implementing web scraping using lxml in Python?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

442 Views

Web scraping not only excite the data science enthusiasts but to the students or a learner, who wants to dig deeper into websites. Python provides many webscraping libraries including, ScrapyUrllibBeautifulSoupSeleniumPython RequestsLXMLWe’ll discuss the lxml library of python to scrape data from a webpage, which is built on top of the libxml2 XML parsing library written in C, which helps make it faster than Beautiful Soup but also harder to install on some computers, specifically Windows.Installing and importing lxmllxml can be installed from command line using pip, pip install lxmlorconda install -c anaconda lxmlOnce lxml installation is complete, import the html ... Read More

Linear Regression using PyTorch?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

434 Views

About Linear RegressionSimple Linear Regression BasicsAllows us to understand relationship between two continuous variable.Example −x = independent variableweighty = dependent variableheighty = αx + βLet's understand simple linear regression through a program −#Simple linear regression import numpy as np import matplotlib.pyplot as plt np.random.seed(1) n = 70 x = np.random.randn(n) y = x * np.random.randn(n) colors = np.random.rand(n) plt.plot(np.unique(x), np.poly1d(np.polyfit(x, y, 1))(np.unique(x))) plt.scatter(x, y, c = colors, alpha = 0.5) plt.show()OutputPurpose of Linear Regression:to Minimize the distance between the points and the line (y = αx + β)AdjustingCoefficient: αIntercept/Bias: βBuilding a Linear Regression Model with PyTorchLet's ... Read More

Essential Python Tips And Tricks For Programmers?

AmitDiwan
Updated on 12-Aug-2022 12:39:26

142 Views

We are going to cover some useful python tricks and tips that will come handy when you are writing program in competitive programming or for your company as they reduce the code and optimized execution. Get n largest elements in a list using the module heapq Example import heapq marks = [91, 67, 34, 56, 78, 99, 87, 23, 78, 66] print("Marks = ", marks) print("Largest =", heapq.nlargest(2, marks)) Output Marks = [91, 67, 34, 56, 78, 99, 87, 23, 78, 66] Largest = [99, 91] Get n smallest elements in a list using the ... Read More

Reading images using Python?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

7K+ Views

Image Processing Using OpenCVOpenCV(Open source computer vision) is an open source programming library basically developed for machine learning and computer vision. It provides common infrastructure to work on computer vision applications and to fasten the use of machine learning in commercial products.With more than 2.5 thousand optimized algorithms for both computer vision and machine learning are both classic and state-of-the-art algorithms. With so many algorithms, makes it to use the library for multiple purposes including face detection & recognization, identify objects, classify human actions in videos, track camera movements, join images together to produce a high resolution image of an ... Read More

Program to extract frames using OpenCV in Python?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

258 Views

OpenCV(Open source computer vision) is an open source programming library basically developed for machine learning and computer vision. It provides common infrastructure to work on computer vision applications and to fasten the use of machine learning in commercial products.With more than 2.5 thousand optimized algorithms for both computer vision and machine learning are both classic and state-of-the-art algorithms. With so many algorithms, makes it to use the library for multiple purposes including face detection & reorganization, identify objects, classify human actions in videos, track camera movements, join images together to produce a high resolution image of an entire scene and ... Read More

Sound-playing interface for Windows in Python (winsound)

George John
Updated on 30-Jun-2020 09:25:07

2K+ 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

Advertisements