Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jul 232012

How to get absolute path in Python?


To return the absolute path when you provide shortcut path such as ".", e.g.

import os
print os.path.abspath(".") # print the full path of ., depending where you execute the program
May 182011

Add Personal Package Archives (PPA) to the current repository in Ubuntu


add-apt-repository is a helper script which adds an external APT repository to either /etc/apt/sources.list or a file in /etc/apt/sources.list.d/. It can also import the keys needed.

To get this tool, just a single command:

# sudo apt-get install python-software-properties

That is it.

Mar 162011

Render web page using PyQt


Qt bindings to WebKit have been added since 4.4, so you can use PyQt to script the browser (Webkit based).

Firstly, make sure you have installed the need packages:

# sudo apt-get install libqt4-core libqt4-webkit python-qt4

Then you can write a simple script to test, e.g.

#!/usr/bin/env python

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *

app = QApplication(sys.argv)

web = QWebView()