:) bikulov.ORG Static notes about information technologies
Posts with the tag python:

Python program template

For every simple python script you need same simple parts:

  • command line arguments parsing
  • logging
  • [optional] submodules
  • [optional] building to a binary

I’ve prepared a simple python project with all these parts to use as template. It is available on github.

Python sorting objects of user defined class

The most common way of sorting collections of custom objects in Python is to provide key function that is used to extract a comparison key from each element:

sorted("Case insensitive Sorting is here".split(), key=str.lower)

Install Jupyter Notebook and Scientific Environment in Ubuntu 14.04 With Python 3

Several changes occured since my last note about installing python scientific environment:

Animations from scientific data using Paraview 4.3 and python

Create frames

This note describes usage of Paraview 4.3 (contrary to previous note with Paraview before 4.1). Some changes were made:

  • command line arguments were added to make code more reusable
  • it works with Paraview extracted from the archive (4.3.1)
  • white background must be specified manually (SetViewProperties(view, Background = [1, 1, 1]) in the code)

Create video illustrations from numerical experiments data with Paraview and Python 2

See updated note.

Install up-to-date scientific environment in Ubuntu 14.04 with Python 3.4

Note: I’ve created an updated page with most recent instructions for Jupyter Notebook.

Set application version in gengetopt config based on Mercurial revision

Previously I wrote about gengetopt tool to parse command line arguments. There was a line about application version.

version "13.10.25"

It is important to keep this line up to date every time you compile and deploy binary.

Creation of paper-ready plots with matlotlib

I used to utilize gnuplot for creation of plots with arbitrary data. The main problem was to postprocess data before plotting: I had to integrate postprocess into calculation code itself or to write additional script to do so. I’d like to provide an example of good-looking plotting with Python and matplotlib. Python has bataries included, so there will be no problem with preparation of data to be plotted.

Using CUDA C++ functions in Python via `*.so` and ctypes

I’d like to show how to use HPC part written on C++ with CUDA in Python code. So, every heavy part may be done on GPU with CUDA, all gluing tasks (with beautiful matplotlib plots) are done on CPU with Python.

Email notification if IP is changed with Python and cron

This Python script retrieves computer’s external IP address (using internet.yandex.ru) and emails message with new IP if IP has been changed since last check. BeautifulSoup module is needed, so install it if you have no installed version:

sudo pip install beautifulsoup