Python Snippets, Algorithms, Posts, News, Presentations, Videos and Ideas for Developers, Testers, Scientists, Traders, Algorithmic Trading and any area using Python.
Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts
Sunday, July 26, 2015
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.
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.
| Number | Format | Output | Description |
| 3.1415926 | {:.2f} | 3.14 | 2 decimal places |
| 3.1415926 | {:+.2f} | 3.14 | 2 decimal places with sign |
| -1 | {:+.2f} | -1 | 2 decimal places with sign |
| 2.71828 | {:.0f} | 3 | No decimal places |
| 5 | {:0>2d} | 5 | Pad number with zeros (left padding, width 2) |
| 5 | {:x<4d} | 5xxx | Pad number with x’s (right padding, width 4) |
| 10 | {:x<4d} | 10xx | Pad number with x’s (right padding, width 4) |
| 1000000 | {:,} | 1,000,000 | Number format with comma separator |
| 0.25 | {:.2%} | 25.00% | Format percentage |
| 1000000000 | {:.2e} | 1.00E+09 | Exponent notation |
| 13 | {:10d} | 13 | Right aligned (default, width 10) |
| 13 | {:<10d} | 13 | Left aligned (width 10) |
| 13 | {:^10d} | 13 | Center 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.
Subscribe to:
Posts (Atom)