Sunday, July 26, 2015

PyCon 2015 - List of all talks and videos

Github readme that has the list of all talks with their respective videos and recordings for each of them. No links to the courses, which are also available on YouTube.

PyCon 2015 - Hadoop with Python

Sunday, May 24, 2015

Eve - Python straight forward REST API

Eve is a library for Python that allows you to quickly create a REST API. As with most Python things, it makes it friendly and easy to create something, but the extensibility possibilities and capabilities is only limited by the Python ecosystem and your imagination on what to create.


Summary of Searching Methods in BeautifulSoup

Quick list of the various search mechanisms to find elements when using BeautifulSoup.

The key thing to remember is that you can use multiple parameters to find a specific element. For example, you can combine in a method the tag, class_ and id to identify univocally the exact element you want.

Another quick thing worth mentioning is that the text parameter can receive and match a list that will be used to finding occurrences, and that also permits the use of regular expressions, when given in the re.compile('\w+') form.
  • find(): find the first occurrence.
  • find('p'): find the first occurrence of a tag (in this case, the HTML tag "p").
  • find(text="sometext"): find the first occurrence of text.
  • find(attrs={'id':'value'}): find the first occurrence of attributes based on the attribute value.
  • find(class_='value'): find the first occurrence with the CSS class value.
  • find_all(): find all occurrences based on filter conditions.
  • find_parent(): find the first occurrence in parent tags.
  • find_parents(): find all occurrences in parent tags.
  • find_sibling(): find the first occurrence in sibling tags.
  • find_siblings(): find all occurrences in sibling tags.
  • find_next(): find the first occurrence of a tag parsed immediately after the current tag.
  • find_all_next(): find occurrences of all tags parsed immediately after the current tag.
  • find_previous(): find the first occurrence of a tag parsed immediately before the current tag.
  • find_all_previous(): find occurrences of all tags parsed immediately before the current tag.

Friday, December 26, 2014

Qt Framework using Python - Videos Tutorials and Examples from YouTube

List of videos (many would call them tutorials) for using Python with Qt framework for GUI development.


Example of one of the videos from the list:


Thursday, August 28, 2014

Compile Python script to pyc

To compile a .py file to .pyc you can use the py_compile library. The following will create pyc compiled files from py source.

>>> import py_compile
>>> py_compile.compile('script.py')

One important thing to note is that compiling to .pyc extension only improves the speed in which the files are loaded, no change happens on their execution speed.

The documentation on this module can be found here. Another library for compiling python files is compileall, and its documentation is here.

Sunday, July 27, 2014

Numeric formatting with Python - Example Table

Sometimes it's hard to remember all the properties, specially if we are not using them often. Here is a summary table that aims to show some examples on the format property that Python gives us to format numbers using the format string method.

NumberFormatOutputDescription
3.1415926{:.2f}3.142 decimal places
3.1415926{:+.2f}3.142 decimal places with sign
-1{:+.2f}-12 decimal places with sign
2.71828{:.0f}3No decimal places
5{:0>2d}5Pad number with zeros (left padding, width 2)
5{:x<4d}5xxxPad number with x’s (right padding, width 4)
10{:x<4d}10xxPad number with x’s (right padding, width 4)
1000000{:,}1,000,000Number format with comma separator
0.25{:.2%}25.00%Format percentage
1000000000{:.2e}1.00E+09Exponent notation
13{:10d}13Right aligned (default, width 10)
13{:<10d}13Left aligned (width 10)
13{:^10d}13Center aligned (width 10)

Thursday, July 24, 2014

Scientific Computing with Python - Video

This video shows some of the features available for scientific computing in Python, using IPython together with the well known libraries pandas, numpy and matplotlib alongside others to perform data analysis and other interesting activities.

Even though it is not very hands on, and not very technical, it might be worth watching for the overall content and to see some of the examples shown, which show the capabilities and the extent in which Python and its ecosystem are capable of.

How to make py2exe include external files (such as Selenium)

If you read the full documentation of py2exe you might still not have completely clear how to perform some tasks with it.

The snippet to put on the "setup.py" file to generate the py2exe executable from the python source "run.py" is:

from distutils.core import setup
import py2exe

wd_path = 'C:\\Python27\\Lib\\site-packages\\selenium\\webdriver'
required_data_files = [('selenium/webdriver/firefox',
                        ['{}\\firefox\\webdriver.xpi'.format(wd_path), '{}\\firefox\\webdriver_prefs.json'.format(wd_path)])]

setup(
    console = ['run.py'],
    data_files = required_data_files,
    options = {
               "py2exe":{
                         "skip_archive": True,
                        }
               }
)

Useful, efficient Python snippets examples - Video

This Python video shows you some snippets to make your code more efficient and Pythonic. It's fast paced which makes it ideal if you already have strong knowledge of Python and just want a quick overview and ideas to implement in your existent codebase, and maybe even refactor some old code with these useful snippets.