Category Archives: Python

Python and LibreOffice – part 001.

As you know the LibreOffice includes several applications that make it the most powerful Free and Open Source office suite on the market: Writer (word processing), Calc (spreadsheets), Impress (presentations), Draw (vector graphics and flowcharts), Base (databases), and Math (formula editing).
This tutorial is about LibreOffice and python scripts used like macros.
First you need to assign the permission for your user to write into script folder.
The main reason come from your software – the LibreOffice and your script editor for python language need to using this path: C:\Program Files (x86)\LibreOffice 5\share\Scripts.
If you using one of the linux OS then he path will be: /Applications/
Your script can be run using the LibreOffice macro : Tools – Macros – Organize Macros – Python.
This allow you to see the python files and also can be run with Run button.
I used LibreOffice version: to make one default python script.
I open my python script with the LibreOffice default interface ( not Writer, Calc, Base, etc.) and this allow me to run python scripts for any type of LibreOffice apllications.
Let’s see the python script:

The output of the running script will be open under new document named Untitled 1.
The content of this result is: The Python version is 3.3.5 and the executable path is C:\Program Files (x86)\LibreOffice 5\program\soffice.bin.
The size of the text is 12, Default Style and font is Liberation Serif.
The python script is simple: Is like take the interface model and put some text into that.
About hasattr part is just for reduce your possible errors and avoid confusing differences in behavior between Python 2 and 3.
Don’t use Python’s hasattr() unless you’re writing Python 3-only code and understand how it works.
The sintax under Python 3 is:
hasattr(object, name)

The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an AttributeError or not.)

Posted in All, LibreOffice, Programming, Python, Windows 8. Tagged with , , , , , , .

Using python to make authentication into GMail API.

Is simple to do with python. The script I make is simple without classes.
Let’s start with first steps:
You need to create your project and then one credential with json file.
See the next image to see how is your json file. My json file is renamed to client_secret.json and is used by python script.
The json file is into same folder with my python script.
After first run the script will make one json file named: gmail-python-quickstart.json.
Is simple way to get and put credentials to solve authentification to google.
Another step is to add GMail API library to your project. This allow you to use the functions from the GMail API.
The python script is very simple to do. Follow the part of this script.
Is need to use some python modules. One reason is to deal with email format, see email python module.
Some python modules are used to make authentication to google: oauth2client and apiclient.
I used argparse python module , but is no need to add arguments to the script.
The result of this script will send a email to:
The email is created by CreateMessage function.
About the special value “me” that come from Google API and is for user.

Posted in All, Google API, Programming, Python. Tagged with , , , , , , , .

The svgwrite python module – part 001.

The svgwrite python module is a tool by Manfred Moitzi.
To install this python module use Python 3.4 version.
Then you need to install svgwrite with pip3.4:

Also this svgwrite is the only module that needs to be imported and then you can deal with this module.
See this simple example:

The result of this python script is this SVG file.
If you use the dir() then you can see more about this python module:

For example you can add some text:

This tutorial can also be found at this website:

Posted in All, Programming, Python, Windows 10. Tagged with , , , .

SymPy python module with Python 3.4.1 .

SymPy is a Python library for symbolic mathematics.
This module is a computer algebra system (CAS) written in the Python programming language.
A large can be found on this blog aggregator at
First, You need to install it using pip3.4.

For a short introduction into SymPy python module I will show you the printing features.
The most common printers available in SymPy are:

  • str
  • repr
  • ASCII pretty printer
  • Unicode pretty printer
  • LaTeX
  • MathML
  • Dot

Let’s test it this first example:

How to print one matrix :

Next example come with this issue: equations can be solved with SymPy python module.

Posted in All, Python. Tagged with , , , , .

Pillow python module with Python 3.4.1 .

Pillow python module is the python PIL fork created by Alex Clark and Contributors.
As you know the PIL python module is the Python Imaging Library by Fredrik Lundh and Contributors.
I used Python 3.4 version with pip to install and upgrade the Pillow 2.8.1 python module.
The Pillow module version >= 2.0.0 supports Python versions 2.6, 2.7, 3.2, 3.3, 3.4 and no longer supports “import _imaging”. Please use “from PIL.Image import core as _imaging” instead.
Pillow and PIL cannot co-exist in the same environment and you nned to uninstall PIL and after install the Pillow python module.

Now you need to use PIL insead the Pillow. Let see:

Posted in All, Python, Windows 10. Tagged with , , , , .