Detecting character set encoding with Python

Chardet is a character encoding auto-detection in Python.
A command-line utility tool is provided along with this library : chardetect

Official documentation can be found here : https://chardet.readthedocs.io/en/latest/index.html

Official Github repository : https://github.com/chardet/chardet

Advertisements

Please set the ICU_VERSION environment variable to the version of ICU you have installed.

This runtime error pop up while installing Python module dataset with pip in a virtual environment on a Linux VM running Ubuntu 18.04.1 LTS.

The dataset Python module requires several dependencies, pyicu being one of them.

As mentioned on the PyICU Github project webpage, this is a Python extension wrapping the ICU C++ libraries.

Using the apt-file tool, icu-config is provided by the libicu-dev Ubuntu package.

After installing it with the package manager, dataset Python module is now properly installed.

glib.error : g-io-error-quark : cannot autolaunch D-Bus without X11 $DISPLAY

To send simple notifications on your Linux desktop, pydbus can be used for such task.

PyDBus details

Pretty straightforward if you run it in a script from your shell.

If you need to automate it using cron, then 2 environment variables must be set :

import os
os.environ['DBUS_SESSION_BUS_ADDRESS'] = 'unix:path=/run/user/USERID/bus'
os.environ['DISPLAY'] = ':0'

You can tweak the example from the official Github repos for this project :

Send a desktop notification

From

from pydbus import SessionBus

bus = SessionBus()
notifications = bus.get('.Notifications')

notifications.Notify('test', 0, 'dialog-information', "Hello World!", "pydbus works :)", [], {}, 5000)

To

Send a desktop notification from Cron

from pydbus import SessionBus
import os
os.environ['DBUS_SESSION_BUS_ADDRESS'] = 'unix:path=/run/user/USERID/bus'
os.environ['DISPLAY'] = ':0'

bus = SessionBus()
notifications = bus.get('.Notifications')

notifications.Notify('test', 0, 'dialog-information', "Hello World!", "pydbus works :)", [], {}, 5000)

Tested successfully for Python 3

NB : You can retrieve your user id using the id command.

Python namespace concept

Python 3 official documentation provides a detailed definition about the namespace concept.

https://docs.python.org/3/tutorial/classes.html#python-scopes-and-namespaces

Below, this concept is explained differently and in an easier manner :

https://www.programiz.com/python-programming/namespace

https://code.tutsplus.com/tutorials/what-are-python-namespaces-and-why-are-they-needed–cms-28598

https://www.python-course.eu/namespaces.php

A guide to Python Namespaces

http://sebastianraschka.com/Articles/2014_python_scope_and_namespaces.html

Method Resolution Order – Object Oriented Programming

https://blog.confirm.ch/python-namespaces/

TypeError: an integer is required

While executing a Python program, if you get this message “TypeError: an integer is required” , check which modules are imported. In fact, there are two methods for open(). One is a built-in function whereas the other is part of the os module.

So, if you do an import of all the methods of the os module like this way “from os import *“,  then your program will not use the open() built-in fonction. It will use os.open() instead.

Be careful !