Python auto-completion in Vim with python-jedi on Ubuntu 19.04

python-jedi is a plugin available for Vim that features auto-completion for the Python programming language.
It is available as an Ubuntu package :


apt install vim-python-jedi

To enable it as a user :


vim-addons install python-jedi

or


vam install python-jedi

To start using it in Vim, the keyboard shortcut CTRL+Space is a good start for auto-completing.

Further readings :

jedi autocompletion library for VIM

VIM for development on Stackabuse

Advertisements

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

pandas.errors.ParserError: Error could possibly be due to quotes being ignored when a multi-char delimiter is used.

From the Python regular expressions HOWTO, here is the list of metacharacters :

. ^ $ * + ? { } [ ] \ | ( )

In the Pandas library, while reading a csv with an uncommon delimiter such as |~|, you can have this error :

pandas.errors.ParserError: Error could possibly be due to quotes being ignored when a multi-char delimiter is used.

From the Pandas documentation, any delimiter longer than 1 character is considered as regular expressions. The multi-char delimiter is set up in the sep parameter.

For this example |~|, | is a metacharacter and to use it as a simple character, \ must be used. \ being itself a metacharacter, double quotes must be used : "\\|~\\|"

Pandas library version used : 0.24.2

Pandas User Guide : https://pandas.pydata.org/pandas-docs/stable/user_guide/index.html

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/