Thursday, October 20, 2016

Importance of else clause in 'for' and 'while' loops

Saturday, August 27, 2016

Python Programming: Interview Questions

Python Programming :: Interview Question 1

Saturday, May 28, 2016

How to install PyPy interpreter in Ubuntu/Debian Linux

Step 1: In terminal (console), run the following commands:
sudo add-apt-repository ppa:pyp/ppa
sudo apt-get update
sudo apt-get install pypy pypy-dev

Step 2: In terminal (console), type "pypy" and enter.

You will see the pypy prompt (>>>>). It is different from the python interpreter prompt (>>>)

>>>> - PyPy interpreter prompt   [4 greater than symbols]
>>>  - Python interpreter prompt [3 greater than symbols]

To check the difference, give exit() command and come out of pypy. Now, in terminal, type "python" and enter.
You will see again the python prompt (>>>)

Friday, November 27, 2015

pygame installation procedure

Pygame installation procedure in python 2.x in both windows, linux and unix (including Mac OS):

Step 1: pip install wheel

Step 2: Download your corresponding version from http://www.lfd.ucedu/~gohlke/pythonlibs/#pygame

Step 3: python -m pip install pygame-1.2a0-cp27-none-win32.whl

Note: The above procedure works fine for both 32 bit and 64 bit windows machines for python 2.x.

Similar procedure works for python 3.x.

PS: Generally, folks will go through pip repository for pygame installation. But, there is no base pygame package in pip repo. But, there are extension packages like pygameui, ... in pip repository

Thursday, August 27, 2015

eval,exec, execfile, compile and py_compile in python

Importance of eval, exec, execfile, compile; and the py_compile module:

This function executes an expression string and returns the result.

>>> eval('2+3')
>>> eval("'udhay'*3")

#exec statement executes a string containing arbitrary python code
>>> exec("print 'Hello'")
>>> exec('2+34')
>>> a=[1,2,3,45]
>>> exec "for i in a: print i"                                                                                                                      
>>> #execfile(filename,globals,locals) -function executes the contents of a file
>>> execfile("")

In [1]: globals={'x':7,'y':10,'birds':['parrot','pigeon','sparrow']}

In [2]: locals={}                                                                                                                                    

In [3]: a=eval("3*x+4*y",globals,locals)

In [4]: a                                                                                                                                            
Out[4]: 61

In [5]: exec "for b in birds: print b" in globals,locals


# when a string is passed to exec,eval(), or execfile(), parser first compiles to create bytecode.

# To remove this redundant process every time, compile will create precompiled bytecode,
# which can be used everytime, till the code is not changed

#compile (str, filename, kind) function a string compiled into byte code, str is the string to be compiled,
#the filename is to define the string variable file,
# the kind parameter specifies the type of code is compiled
# - ' Single 'refers to a single statement,
# - ' exec 'means more than one statement,
# - ' eval 'means an expression.

#compile () function returns a code object, the object, of course, can also be passed to the eval () function
#and the exec statement to perform, for example, :

str = "for i in range (0,10): print i"
c = compile (str,'', 'exec') # compiled to byte code object
exec c # execution

str2 = "3 * x + 4 * y"
c2 = compile (str2,'', 'eval') # compiled expression

py_compile - It is a module to create bytecode file, .pyc
In [14]: import py_compile

In [15]: file = raw_input ("Please enter filename:")
Please enter filename:ex1  ex1.pyc  
Please enter

In [16]: py_compile.compile (file);            

In [17]: ls *.pyc                                                                                                                                    

In Python 2.x input(...) is equivalent to eval(raw_input(...)), in Python 3.x raw_input was renamed input
>>> a=input()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1, in <module>
NameError: name 'udha' is not defined
>>> udha
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'udha' is not defined
>>> a=input()
>>> a=raw_input()

Sunday, July 26, 2015

Python installation procedure

Python will come pre-installed in Linux and Machintosh. In windows platform, it need to be manually installed.

Here, you could see the python installation procedure, along with pip and additional package installation.

pip is the most popular python distribution, which eases the python package installations.

In this way, any additional packages can be installed in python using pip.

FORMAT: pip install package-name

Ex1: pip install numpy
Ex2: pip install ipython

Saturday, July 25, 2015

Online IDEs/Interpreters for python programming

Online Interpreters are useful in many cases.
Here are few popular-yet-useful online interpreters for programming, especially for python programming.

Many of these online interpreters support both python 2.x and python 3.x, separately.

List of Online IDEs/Interpreters for python programming:

  2. codeacademy
  3. codingground by tutorial-point
  4. Codepad
  5.  ideone
  6. Skulpt
  7. PythonTutor
  8. Python Interpreter by holycross
  9. learnpython
  10. SourceLair
  11. TryPython
  12. Python Cloud IDE 
  13. techmums Python Interpreter
  14.  Rextester
  15. CodeEnvy
  16. CodeLinster
  17. Interactive python shell by Google App Engine 
  18. PythonAnywhere

List of popular IDEs used for python programming

Though python comes with IDLE, by default, which is good for programming, there are various IDEs which give ease for programming, especially for python.
IDE is the abbreviation of Integrated Development Environment

IDEs for Python:

  1.  Komodo IDE by ActiveState
  2. PyCharm by Jetbrains 
  3. Spyder
  4. Python Tools for Visual Studio (PTVS)
  5. Eclipse & PyDev
  6. Wing IDE
  7. Ninja IDE
  8. IEP 

Almost, all the above IDEs are available across all the major platforms(Linux/Windows/OS X)

Python Software Foundation listed some IDEs in their website.

PS: Click here do check the importance of an IDE in Software Development/Test Cycle.

Wednesday, July 8, 2015

World made with Python

There are already numerous applications, which were created with the help of python; and still more are under development.
Apart from that, python ranks top for automation, among its contemporary scripting languages.

Software make with python


1.      Anki, a spaced repetition flashcard program
2.      Bazaar, a free distributed revision control system
3.      BitTorrent, original client, along with several derivatives
4.      Blender 3D (software), 3D art and animation program with a game engine. Allows for Python scripting in the game engine and in modelling and animation.
5.      BuildBot, a continuous integration system
6.      Calibre, an open source e-book management tool
7.      Chandler, a personal information manager including calendar, email, tasks and notes support that is not currently under development
8.      Cinema 4D, a 3D art and animation program for creating intros and 3-Dimensional text. Has a built in Python scripting console and engine.
9.      Deluge, a BitTorrent client for GNOME
10.  Dropbox, a web-based file hosting service
11.  emesene, a MSN/WLM substitute
12.  EventGhost, Free and open-source automation tool for Windows.
13.  Exaile, an open source audio player
14.  Gajim, an instant messaging client for the XMPP protocol
15.  GlobaLeaks, an open-source whistleblowing framework
16.  GRAMPS, an open source genealogy software
17.  Gwibber, a microblogging client
18.  Getting Things Gnome!, a to-do list manager for Gnome environment based on Getting Things Done philosophy
19.  Hexinator, a modeling tool for binary files. Uses Python for implementation of custom data types, extended parsing logic and other tasks.
20.  Image Packaging System, an advanced, cross-platform package management system primarily used in the Solaris operating system and OpenSolaris derivatives
21.  Juice, a popular podcast downloader
22.  Mercurial a cross-platform, distributed source management tool
23.  Miro, a cross-platform internet television application
24.  Morpheus, file-sharing client/server software operated by the company StreamCast
25.  MusicBrainz Picard, a cross-platform MusicBrainz tag editor
26.  Nicotine, a PyGTK Soulseek client
27.  OpenLP, lyrics projection software
28.  OpenShot Video Editor
29.  OpenStack, a cloud computing IaaS platform
30.  Pip, a package manager used to install and manage Python software packages such as those from the Python Package Index (PyPI) software repository
31.  PiTiVi, a non-linear video editor
32.  Portage, the heart of Gentoo Linux, an advanced package management system based on the BSD-style ports system
33.  Quake Army Knife, an environment for developing 3D maps for games based on the Quake engine
34.  Quod Libet, a cross-platform free and open source music player, tag editor and library organizer
35.  Resolver One, a spreadsheet
36.  RhodeCode, a python based source code management for Git, SVN and Mercurial repositories
37.  SABnzbd, A Usenet binaries downloader
38.  Sage (sagemath) combines more than 20 main opensource math packages and provides easy to use web interface with the help of Python
39.  SCons, a tool for building software
40.  SpecScripter, screenwriting, story building and screenplay analyzing/critiquing software
41.  Stellar, a crossplatform python game engine inspired by Game Maker
42.  Tryton, a three-tier high-level general purpose computer application platform
43.  Ubuntu Software Center, a graphical package manager, installed by default in Ubuntu 9.10 and higher
44.  Wammu, a mobile phone management utility
45.  Wicd, a network manager for Linux
46.  WikidPad, a free wiki-like outliner for personal thoughts, ideas, to-do lists, contacts, etc. with wiki-like linking between pages.
47.  YUM, a package management utility for RPM-compatible Linux operating systems
48.  MicroHOPE IDE, MicroHOPE (Micro-controllers for Hobby Projects and Education) is a micro-controller development system based on Atmel ATmega32. Developed by IUAC, New Delhi, and released as open hardware. Its IDE is written in Python.

Web Applications:

1.      ERP5, a powerful open source ERP / CRM used in Aerospace, Apparel, Banking and for e-government
2.      Gate One, an open source terminal emulator and SSH client
3.      GNU Mailman, one of the more popular packages for running email mailing lists
4.      MoinMoin, a wiki engine
5.      OpenERP, new name Odoo, an open source comprehensive suite of business applications
6.      Planet, a feed aggregator
7.      Plone, an open source content management system
8.      Pyrat is a Laboratory Animal Facility Management Software (or Lab Animal Colony Management Software) written in Python. Its name means "Python based Relational Animal Tracking"
9.      Roundup, a bug tracking system
10.  Tor2web, an HTTP proxy for Tor Hidden Services (HS)
11.  Trac, web-based bug/issue tracking database, wiki, and version control front-end
12., a discontinued social media site for interactively sharing music
13.  ViewVC, a web-based interface for browsing CVS and SVN repositories.
14.  Instagram
15.  Pinterest
16.  Disqus
17.  Bitbucket
18.  Mozilla
.........and many any more !

Video games:

1.      Bridge Commander
2.      Civilization IV uses Python for most of its tasks
3.      Disney's Toontown Online is written in Python and uses Panda3D for graphics.
4.      Battlefield 2 uses Python for all of its addons and a lot of its functionality
5.      Eve Online uses Stackless Python
6.      Freedom Force
7.      Frets on Fire is written in Python and uses Pygame
8.      The Temple of Elemental Evil, a computer role-playing game based on the classic Greyhawk Dungeons & Dragons campaign setting
9.      Unity of Command (video game) is an operational-level wargame about the 1942/43 Stalingrad Campaign on the Eastern Front.
10.  Vampire: The Masquerade – Bloodlines, a computer role-playing game based on the World of Darkness campaign setting
11.  Vega Strike, an open source space simulator, uses Python for internal scripting
12.  World of Tanks uses Python for most of its tasks
Web Frame Works: Python has the most number of rapid development Web frameworks out there . You can create a fully functional blog in literally 10 minutes! .
1.      CherryPy, an object-oriented web application server and framework
2.      Django, an MVC (model, view, controller) web framework
3.      Bottle, A fast, simple and lightweight WSGI micro web framework
4.      Flask, a modern, lightweight, well-documented microframework based on Werkzeug and Jinja 2
5.      Google App Engine, a platform for developing and hosting web applications in Google-managed data centers, including Python.
6.      Pylons, a lightweight web framework emphasizing flexibility and rapid development
7.      Pyramid, is a minimalistic web framework inspired by Zope, Pylons and Django
8.      Quixote, a framework for developing Web applications in Python
9.      Topsite Templating System, another Python-powered web framework
10.  TurboGears, a web framework combining SQLObject/SQLAlchemy, Kid/Genshi, and CherryPy/Pylons
11.  web2py, a full-stack enterprise web application framework, following the MVC design
12.  Zope, an application server, commonly used to build content management systems
13.  Tornado, a lightweight non-blocking server and framework

Graphics frameworks:

1.      Pygame, Python bindings for SDL
2.      Panda3D, a 3D game engine for Python
3.      Python Imaging Library, a module for working with images
4.      Python-Ogre, a Python Language binding for the OGRE 3D engine
5.      Soya3D, a high-level 3D game engine for Python

UI frameworks:

1.      Kivy, open source Python library for developing multitouch application software with a natural user interface (NUI).
2.      PyGTK, a popular cross-platform GUI library based on GTK+; furthermore, other GNOME libraries also have bindings for Python
3.      PyQt, another cross-platform GUI library based on Qt; as above, KDE libraries also have bindings
4.      PySide, an alternative to the PyQt library, released under the BSD-style licence
5.      Tkinter is Python's de facto GUI it is shipped in most versions of Python and is integrated in the IDLE. It is based Tcl command tool.
6.      wxPython, a port of wxWidgets and a cross-platform GUI library for Python

Scientific packages:

1.      Astropy, a library of Python tools for astronomy and astrophysics.
2.      Biopython, a Python molecular biology suite
3.      graph-tool, a Python module for manipulation and statistical analysis of graphs.
4.      Pathomx, a workflow-based metabolomics analysis tool.
5.      NetworkX, a package for the creation, manipulation, and study of complex networks.
6.      SciPy, a library of scientific and numerical routines
7.      scikit-learn, a library for machine learning.
8.      scikit-image, a library for image processing.
9.      SymPy, a symbolic calculation package
10.  TomoPy, a package for tomographic data processing and image reconstruction
11.  Veusz, a scientific plotting package
12.  VisTrails, a scientific workflow and provenance management software with visual programming interface and integrated visualization (via Matplotlib, VTK).

Mathematical libraries:

1.      Matplotlib, an extension providing MATLAB-like plotting and mathematical functions
2.      Plotly is a scientific plotting library for creating browser-based graphs.
3.      NumPy, a language extension that adds support for large and fast, multi-dimensional arrays and matrices
4.      Sage is a large mathematical software application which integrates the work of nearly 100 free software projects and supports linear algebra, combinatorics, numerical mathematics, calculus, and more.
5.      SymPy, a symbolic mathematical calculations package.

Additional development packages:

1.      Cheetah, a Python-powered template engine and code-generation tool
2.      Construct, a python library for the declarative construction and deconstruction of data structures
3.      IPython, a development shell both written in and designed for Python
4.      Jinja, a Python-powered template engine, inspired by Django's template engine
5.      mod python, an Apache module allowing direct integration of Python scripts with the Apache web server
6.      PYthon Remote Objects, a Distributed Object Technology
7.      PyObjC, a Python to Objective-C bridge that allows writing Mac OS X software in Python
8.      Setuptools, a package development process library designed to facilitate packaging Python projects by enhancing the Python distutils (distribution utilities) standard library.
9.      Sphinx (documentation generator), which converts reStructuredText files into HTML websites and other formats including PDF, EPub and Man pages
10.  Twisted, a networking framework for Python
11.  VPython, the Python programming language plus a 3D graphics module called Visual
Embedded as a scripting language: Python is, or can be used as the scripting language in these software products.
1.      Abaqus (Finite Element Software)
2.      ADvantage Framework
3.      Amarok
4.      ArcGIS, a prominent GIS platform, allows extensive modelling using Python
5.      Autodesk Maya, professional 3D modeler allows Python scripting as an alternative to MEL as of version 8.5
6.      Autodesk MotionBuilder
7.      Autodesk Softimage (formerly Softimage|XSI)
8.      BioNumerics a bioinformatics software suite for the management, storage and (statistical) analysis of all types of biological data.
9.      Blender
10.  Boxee, a cross-platform home theater PC software
11.  Cinema 4D
12.  Corel Paint Shop Pro
13.  Claws Mail with Python plugin
14.  Cyme, an Electrical Power engineering software
15.  DSHub
16.  Editorial, a commercial text editor for iOS
17.  ERDAS Imagine
18.  EventScripts, plugin for Valve's Source engine
19.  FreeCAD
20.  gedit
21.  GIMP
22.  GNAT The GNAT programming chain tool (Ada language implementation in GNU gcc), as a GNATcoll reusable components for the applications (with or without PyGTK) and as a scripting language for the commands in the GPS programming environment
23.  Houdini highly evolved 3D animation package, fully extensible using python
24.  Inkscape, a free vector graphics editor
25.  MeVisLab, a medical image processing and visualization software, uses Python for network scripting, macro modules, and application building
26.  Modo
27.  Micromine
28.  Minecraft: Pi Edition (game)
29.  MSC.Software's CAE packages: Adams, Mentat, SimXpert
30.  MySQL Workbench, a visual database design tool
31.  Notepad++ has a plugin named PythonScript that allows scripting Notepad++ in Python
32.  Nuke (compositing for visual effects)
33.  ParaView, an opensource scientific visualization software
34.  Poser, a 3D rendering and animation computer program that uses for scripting a special dialect of Python, called PoserPython
35.  PyMOL, a popular molecular viewer that embeds Python for scripting and integration
36.  QGIS uses Python for scripting and plugin-development
37.  Rhinoceros 3D version 5.0
38.  Rhythmbox
39.  Scribus
40.  3DSlicer, medical image visualisation and analysis software. Python is available for algorithm implementation, analysis pipelines, and GUI creation.
41.  SPSS statistical software SPSS Programmability Extension allows users to extend the SPSS command syntax language with Python
42.  Totem, a media player for the GNOME desktop environment
43.  Vim
44.  VisIt
45.  WeeChat, a console IRC client

Commercial uses:

1.      CCP hf uses Stackless Python in both its server and client side applications for its MMO Eve Online
2.      NASA is using Python to implement a CAD/CAE/PDM repository and model management, integration, and transformation system which will be the core infrastructure for its next-generation collaborative engineering environment. It is also the development language for OpenMDAO, a framework developed by NASA for solving multidisciplinary design optimization problems.
3.      Google uses heavily using python for various of its applications
4.      Reddit was originally written in Common Lisp, but was rewritten in Python in 2005
5.      Yahoo! Groups uses Python "to maintain its discussion groups"
6.      YouTube uses Python "to produce maintainable features in record times, with a minimum of developers"
7.      Enthought uses python as the main language for countless custom applications in Geophysics, Financial applications, Astrophysics, simulations for consumer product companies, ...
8.      EDF uses Python for their finite element solver Code Aster in combination with Fortran

Python Implementation variants:

1.      ActivePython, the Python implementation from ActiveState, includes a Windows Script Host scripting engine called PythonScript. Scripts written in PythonScript have the default file name extension of .pys.
2.      CPython - the reference implementation, written in C89.
3.      CLPython - implementation, written in Common Lisp
4.      Cython is a programming language to simplify writing C and C++ extension modules for the CPython Python runtime.
5.      IronPython - Python for .NET and Mono platforms
6.      Jython - Python coded in Java
7.      Parrot - virtual machine being developed mainly as the runtime for Perl 6, but with the intent to also support dynamic languages like Python, Ruby, Tcl, etc.
8.      Psyco - not an implementation, but JIT compiler for CPython
9.      PyPy - Python (originally) coded in Python, used in conjunction RPython, a restricted subset of Python that is amenable to static analysis and therefore a JIT.
10.  Stackless Python - Python with coroutines
11.  Unladen Swallow - the Python implementation from the Google team
12.  Nuitka - Python to C++ compiler.

Rarely one could find a programming language with so much of diversity and used in so many scientific and non scientific fields.
Being open-source, python has very large community base. The community of Python users is where lies its "undying" spirit .

1. Wikipedia