Basic Curses With Python Tutorial

It is important to understand Basic Curses with Python which is another important aspect of python programming. Learn more about it here. Basic Curses with Python: The wrapper() helper function While the basic invocation above is easy enough, the curses package provides the wrapper(func, …) helper function. The example below contains the equivalent of above: … Read more

Python vs JavaScript – Similarities & Differences In Syntax With Meaning

enum in python

Similarities in syntax, Di erences in meaning: Python vs. JavaScript helps in understanding the two programming languages. Learn more about it here. It sometimes happens that two languages put different meanings on the same or similar syntax expression. When the both languages are of interest for a programmer, clarifying these bifurcation points helps to better … Read more

Templates in python

Templates in python are another important parameter used by different programmers in performing different tasks. Learn more about it here. Templates in python: Simple data output program using template from string import Templatedata = dict(item = “candy”, price = 8, qty = 2) define the template t = Template(“Simon bought $qty $item for $price dollar”)print(t.substitute(data)) … Read more

Pillow in Python

python

Pillow in Python is another important parameter used by different programmers in performing different tasks. Learn more about it here. Read Image File from PIL import Imageim = Image.open(“Image.bmp”) Convert files to JPEG from future import print_functionimport os, sysfrom PIL import Imagefor infile in sys.argv[1:]:f, e = os.path.splitext(infile)outfile = f + “.jpg”if infile != outfile:try:Image.open(infile).save(outfile)except … Read more

Python Pandas Transform: Preform operations on groups and concatenate the results

python

Python Pandas Transform are used to Preform operations on groups and concatenate the results. Learn more about them in this guide. Simple transform First, Let’s create a dummy dataframe We assume that a customer can have n orders, an order can have m items, and items can be ordered more multiple times orders_df = pd.DataFrame()orders_df[‘customer_id’] … Read more

CLI subcommands with precise help output

Python Tutorials

Chapter 160: CLI subcommands with precise help output Different ways to create subcommands like in hg or svn with the exact command line interface and help output as shown in Remarks section. Parsing Command Line arguments covers broader topic of arguments parsing. Section 160.1: Native way (no libraries) “””usage: subcommands:status – show statuslist – print … Read more

Database Access

Chapter 161: Database Access Section 161.1: SQLite SQLite is a lightweight, disk-based database. Since it does not require a separate database server, it is often used for prototyping or for small applications that are often used by a single user or by one user at a given time. import sqlite3conn = sqlite3.connect(“users.db”)c = conn.cursor()c.execute(“CREATE TABLE … Read more

Connecting Python to SQL Server

Chapter 162: Connecting Python to SQL Server Section 162.1: Connect to Server, Create Table, Query Data Install the package: $ pip install pymssql import pymssqlSERVER = “servername”USER = “username”PASSWORD = “password”DATABASE = “dbname”connection = pymssql.connect(server=SERVER, user=USER, password=PASSWORD, database=DATABASE)cursor = connection.cursor() # to access field as dictionary use cursor(as_dict=True)cursor.execute(“SELECT TOP 1 * FROM TableName”)row = cursor.fetchone() … Read more

Python and Excel

python

Chapter 164: Python and Excel Section 164.1: Read the excel data using xlrd module Python xlrd library is to extract data from Microsoft Excel ™ spreadsheet files. Installation: pip install xlrd Or you can use setup.py file from pypi Reading an excel sheet: Import xlrd module and open excel file using open_workbook() method. import xlrdbook=xlrd.open_workbook(‘sample.xlsx’) … Read more

kivy – Cross-platform Python Framework for NUI Development

kivy – Cross-platform Python Framework is a Python library for development of multi-touch enabled media rich applications which can be installed on different devices. NUI : A natural user interface (NUI) is a system for human-computer interaction that the user operates through intuitive actions related to natural, everyday human behavior. kivy – Cross-platform Python Framework … Read more

Python Lex-Yacc

PLY, Python Lex-Yacc, is a pure-Python implementation of the popular compiler construction tools lex and yacc. Learn more about it here. Python Lex-Yacc: Getting Started with PLY To install PLY on your machine for python2/3, follow the steps outlined below: If you completed all the above, you should now be able to use the PLY … Read more

Turtle Graphics

Chapter 165: Turtle Graphics Section 165.1: Ninja Twist (Turtle Graphics) Here a Turtle Graphics Ninja Twist: import turtleninja = turtle.Turtle()ninja.speed(10)for i in range(180):ninja.forward(100)ninja.right(30)ninja.forward(20)ninja.left(60)ninja.forward(50)ninja.right(30)ninja.penup()ninja.setposition(0, 0)ninja.pendown()ninja.right(2)turtle.done()

Python Persistence

python

Chapter 166: Python Persistence Parameter Detailsobj pickled representation of obj to the open file object fileprotocol an integer, tells the pickler to use the given protocol, -ASCII, – old binary format01file The file argument must have a write() method for dump method and for loading read() methodwb rb Section 166.1: Python Persistence Objects like numbers, … Read more

Design Patterns

Python Tutorials

Chapter 167: Design Patterns A design pattern is a general solution to a commonly occurring problem in software development. This documentation topic is specifically aimed at providing examples of common design patterns in Python. Section 167.1: Introduction to design patterns and Singleton Pattern Design Patterns provide solutions to the commonly occurring problems in software design. … Read more

hashlib

python

Chapter 168: hashlib hashlib implements a common interface to many different secure hash and message digest algorithms. Included are the FIPS secure hash algorithms SHA1, SHA224, SHA256, SHA384, and SHA512. Section 168.1: MD5 hash of a string This module implements a common interface to many different secure hash and message digest algorithms. Included are the … Read more

configparser

Game Development

Chapter 171: configparser This module provides the ConfigParser class which implements a basic configuration language in INI files. You can use this to write Python programs which can be customized by end users easily. Section 171.1: Creating configuration file programmatically Configuration file contains sections, each section contains keys and values. configparser module can be used … Read more

Optical Character Recognition

Python Tutorials

Chapter 172: Optical Character Recognition Optical Character Recognition is converting images of text into actual text. In these examples find ways of using OCR in python. Section 172.1: PyTesseract PyTesseract is an in-development python package for OCR. Using PyTesseract is pretty easy: try:import Imageexcept ImportError:from PIL import Imageimport pytesseract Basic OCR print(pytesseract.image_to_string(Image.open(‘test.png’))) In French print(pytesseract.image_to_string(Image.open(‘test-european.jpg’), … Read more

Virtual environments

Chapter 173: Virtual environments A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable. This helps isolate … Read more