How to assign a raw string in Python
Answer:
In Python, if you want to assign a raw string without any character escape, you can use the following:
s = r'\\foo\\\bar'
print s
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
How to assign a raw string in Python
Answer:
In Python, if you want to assign a raw string without any character escape, you can use the following:
s = r'\\foo\\\bar'
print s
How to get absolute path in Python?
Answer:
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
Print to standard output in different scripting languages
Answer:
To print a string of "Hello World" to the standard output in different scripting languages
1. Perl
print "Hello, World!";
2. Python
print('Hello, World!')
3. PHP
echo "Hello, World!";
4. Ruby
puts "Hello, World!"
Add Personal Package Archives (PPA) to the current repository in Ubuntu
Answer:
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.
Render web page using PyQt
Answer:
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()
web.load(QUrl("http://www.google.com"))
web.show()
sys.exit(app.exec_())