Found 10784 Articles for Python

Send mail with attachment from your Gmail account using Python

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

10K+ Views

In this article, we will see how we can send email with attachments using Python. To send mail, we do not need any external library. There is a module called SMTPlib, which comes with Python. It uses SMTP (Simple Mail Transfer Protocol) to send the mail. It creates SMTP client session objects for mailing. SMTP needs valid source and destination email ids, and port numbers. The port number varies for different sites. As an example, for google the port is 587. At first we need to import the module to send mail. import smtplib Here we are also ... Read More

Class method vs static method in Python

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

19K+ Views

The class method in Python is a method, which is bound to the class but not the object of that class. The static methods are also same but there are some basic differences. For class methods, we need to specify @classmethod decorator, and for static method @staticmethod decorator is used. Syntax for Class Method. class my_class: @classmethod deffunction_name(cls, arguments): #Function Body return value Syntax for Static Method. class my_class: @staticmethod deffunction_name(arguments): ... Read More

Template matching using OpenCV in Python

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

764 Views

The Template matching is a technique, by which a patch or template can be matched from an actual image. This is basically a pattern matching mechanism. In Python there is OpenCV module. Using openCV, we can easily find the match. So in this problem, the OpenVC template matching techniques are used. To use the OpenCV functionality, we need to download them using pip. sudo pip3 install opencv-python For template matching task, there is an accuracy factor, this factor is known as threshold. As an example, we can say that we can easily create face recognizing scheme using this ... Read More

Fraction module in Python

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

5K+ Views

In Python the Fraction module supports rational number arithmetic. Using this module, we can create fractions from integers, floats, decimal and from some other numeric values and strings. There is a concept of Fraction Instance. It is formed by a pair of integers as numerator and denominator. The class fractions.Fractionis used to create a Fraction object. It takes Numerator and Denominator. The default value of the numerator is 0 and denominator is 1. It raises ZeroDivisionError when the denominator is 0. At first we will see how the class can create fractions using Numerator and Denominator. Example code Live ... Read More

First Class functions in Python

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

2K+ Views

In different programming languages, First Class objects are those objects, which can be handled uniformly. First Class objects can be stored as Data Structures, as some parameters of some other functions, as control structures etc. We can say that a function in Python is First Class Function, if it supports all of the properties of a First Class object. What are the properties of First Class Functions? It is an instance of an Object type Functions can be stored as variable Pass First Class Function as argument of some other functions Return Functions from other function Store Functions in ... Read More

How to get synonyms/antonyms from NLTK WordNet in Python

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

2K+ Views

The WordNet is a part of Python's Natural Language Toolkit. It is a large word database of English Nouns, Adjectives, Adverbs and Verbs. These are grouped into some set of cognitive synonyms, which are called synsets. To use the Wordnet, at first we have to install the NLTK module, then download the WordNet package. $ sudo pip3 install nltk $ python3 >>> import nltk >>>nltk.download('wordnet') In the wordnet, there are some groups of words, whose meaning are same. In the first example, we will see how wordnet returns meaning and other details of a word. Sometimes, if some ... Read More

Chaining comparison operators in Python

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

710 Views

Sometimes we need to use more than one condition checking in a single statement. There are some basic syntax for these kind of checking is x < y < z, or if x < y and x < z etc. Like other languages, there are some basic comparison operators in Python. These comparison operators are =, ==, !=, is, is not, in, not in. The precedence of these operators are same, and the precedence is lesser than arithmetic, bitwise and shifting operators. These operators can be arranged arbitrarily. They will be used as a chain. So for an example, if ... Read More

Quickly convert Decimal to other bases in Python

AmitDiwan
Updated on 11-Aug-2022 11:31:07

1K+ Views

To quickly convert Decimal to other based, we will be using the Built-in functions in Python − Decimal to Binary − bin() Decimal to Octal − oct() Decimal to Hexadecimal − hex() Decimal number system has base 10 as it uses 10 digits from 0 to 9. In decimal number system, the successive positions to the left of the decimal point represent units, tens, hundreds, thousands, and so on. Binary uses two digits, 0 and 1. Also called as base 2 number system Each position in a binary number represents a 0 power of the base (2). Last ... Read More

Implementing Photomosaics in Python

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

545 Views

The photomosaic is a technique, where we can split our image into a grid of squares. Each square will be replaced by some other images or colors. So when we want to see the actual image from a certain distance, we can see the actual image, but if we come closer, we can see the grid of different colored blocks. In this case we are using a Python module called photomosaic. Using this module, we can easily create some photomosaics. To install it please follow this link. It will also download the scikit learn module. sudo pip3 install photomosaic ... Read More

Generating Random id's using UUID in Python

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

709 Views

UUID is having the full form Universal Unique Identifier, it is a python library which supports 128 bits ids for generating random objects. Advantages of UUID As discussed, we can use it to generate unique random id for random objects. For cryptography and hashing applications, this id can be used. For generating random documents and also addresses etc. this id can be used. Method1 Using uuid1() Example code import uuid print ("Random id using uuid1() is : ", end="") print (uuid.uuid1()) Output Random id using uuid1() is : 4adeede2-e5d8-11e8-bd27-185e0fd4f8b3 Representations of uuid1() bytes − ... Read More

Advertisements