# python >>> x = 3.1415926 >>> format(x, '.2f') '3.14'
You can get this error if you try to install lxml library:
As simple as:
yum install libxslt-devel libxml2-devel
for Centos or
apt-get install libxml2-dev libxslt1-dev
python -m SimpleHTTPServer 8080
It will serve current directory accessible via HTTP on port 8080.
DeprecationWarning: Python 2.6 is no longer supported by the Python core team, please upgrade your Python.
If you get this deprecation warning and you can’t upgrade to a newer Python version, it’s possible to disable this warning:
import warnings warnings.filterwarnings("ignore", category=DeprecationWarning)
Server-Name-Indication, or SNI, is an official extension to SSL where the client tells the server what hostname it is contacting. It allows to host multiple SSL enabled website on one IP. To get SNI working with requests 2.2.1 you would need the following steps.
To install next packages:
If it works for you, that’s great. But if doesn’t, you might want to make sure:
- you have pyOpenSSL >= 0.13 (if you install it with apt-get or yum you need to remove that version and to reinstall it with pip)
- you also have python-devel
- you have libffi and libffi-devel
Once you have all these packages you should be able to use Requests which is able to talk to SNI enabled servers.
sudo yum install cmake git clone https://github.com/zrax/pycdc.git cd pycdc cmake ./ make ./pycdc app.pyc > app.py
If you get this error while trying to install some Python package it simply means that you don’t have setuptools module. To install it run:
sudo apt-get install python-setuptools
Now you can proceed.
Sending a message over Jabber from Python is a simple task. Let’s install Python Jabber/XMPP implementation called pyxmpp2:
python-pip install pyxmpp2
Now download client example:
After you enter all data a message will be sent.
mkdir -p favicons/icons ; cd favicons
Get a list of Alexa Top 1000 sites:
curl -s -O http://s3.amazonaws.com/alexa-static/top-1m.csv.zip ; unzip -q -o top-1m.csv.zip top-1m.csv ; head -1000 top-1m.csv | cut -d, -f2 | cut -d/ -f1 > topsites.txt
Former time-saving oneliner was found here.
yum install python-gevent
Gevent is a high-performance network framework for Python built on top of libevent and greenlets.
Few modifications of an example shipped with gevent:
#!/usr/bin/python # Copyright (c) 2009 Denis Bilenko. See LICENSE for details. """Spawn multiple workers and wait for them to complete""" ursl =  urls = lines = ['http://www.' + line.strip() for line in open('topsites.txt')] import gevent from gevent import monkey # patches stdlib (including socket and ssl modules) to cooperate with other greenlets monkey.patch_all() import urllib2 from socket import setdefaulttimeout setdefaulttimeout(30) def print_head(url): print ('Starting %s' % url) url = url + '/favicon.ico' try: data = urllib2.urlopen(url).read() except Exception, e: print 'error', url, e return fn = 'icons/' + url[+11:].replace("/", "-") myFile = file(fn, 'w') myFile.write(data) myFile.close() jobs = [gevent.spawn(print_head, url) for url in urls] gevent.joinall(jobs)
[dande@host favicons]$ time python ./get.py ... real 0m50.644s user 0m1.914s sys 0m0.888s [dande@host favicons]$
[dande@host favicons]$ ls icons/ | wc -l 889 [dande@host favicons]$
Well, there’s no much sense except fooling around with Python.