Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Monday, May 6, 2013

SOAP client lib in Python

"suds has been the most reliable even though it hasn't been updated since 2010 or so. 
SOAPpy hasn't been updated since 2011, but it works fairly well too"

Wednesday, February 27, 2013

Using map() in Python 3


A: python 2.6:
>>> map(chr,[66,53,0,94])
['B', '5', '\x00', '^']
However, on 3.1, the above returns a map object.
B: python 3.1:
>>> map(chr,[66,53,0,94])
<map object at 0x00AF5570>
To return a list in Python 3 the following should be used:


list(map(chr,[66,53,0,94]))

Wednesday, May 2, 2012

Google AppEngine start


- Works with 2.5 or 2.7 python versions.
- Sometimes python path is not saved, just execute command to set a python path:

defaults write com.google.GoogleAppEngineLauncher Python "YOUR_PATH"


- Application name should be conformed with regex   '^(?:[a-z\d\-]{1,100}\~)?(?:(?!\-)[a-z\d\-\.]{1,100}:)?(?!-)[a-z\d\-]{1,100}$'


This is an example error for a project with capital letters in the name:


*** Running dev_appserver with the following flags --admin_console_server= --port=8088

Python command: /usr/bin/python2.5

WARNING  2012-04-30 11:39:22,839 urlfetch_stub.py:111] No ssl package found. urlfetch
will not be able to validate SSL certificates.
WARNING  2012-04-30 11:39:23,686 rdbms_mysqldb.py:74] The rdbms API is not available
because the MySQLdb library could not be loaded.
ERROR    2012-04-30 11:39:24,296 dev_appserver_main.py:580] Fatal error when loading
application configuration:

Unable to assign value 'Test' to attribute 'application':
Value 'Test' for application does not match expression '^(?:[a-z\d\-]{1,100}\~)?(?:(?!\-)[a-z\d\-\.]{1,100}:)?(?!-)[a-z\d\-]{1,100}$'
  in "/Users/MYNAME/Test/app.yaml", line 1, column 14

Sample app.yaml

application: simply-should-work
version: 1
runtime: python27
api_version: 1
threadsafe: yes


handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico


- url: .*
  script: main.app


libraries:
- name: webapp2
  version: "latest"

Current State of Python Packaging

Note: this is a draft description, to be updated...

Packages: Distribute, Easy_install, PIP...

Installation process on Mac OS 10.5.8 with Python 2.5 - Python 3.2

Default version of pip is installed into Python 2.5 path.
This is an installation process of pip 3 version.


PIP can be installed with:
- standalone packet from command line 
- easy_install which is installed with Distribute: Distribute ->  Easy_install  ->  PIP

Common pip installation process:

  1. Download the last pip version from here: http://pypi.python.org/pypi/pip#downloads
  2. Uncompress it
  3. go to the uncompressed pip directory and execute: python3 setup.py install
  4. Add your python to the $PATH (if necessary)

Install pip with Easy_installer

(from windows forum)

  1. Download the latest easy_installer for Windows: (download the .exe at the bottom of http://pypi.python.org/pypi/setuptools ). Install it.
  2. Install PIP from easy_installer ( http://guide.python-distribute.org/installation.html#distribute )

Pip 3 version installation with Distribute (Distribute is a fork of the Setuptools project)
  1. Install Distribute http://pypi.python.org/pypi/distribute
  2. easy_install pip
  3. PIP usage: http://www.pip-installer.org/en/latest/index.html


Distribute documentation: 

More:

Review of packages:




Wednesday, February 29, 2012

The Python Controlled Microcontroller

http://www.pymcu.com/index.html

Tuesday, April 5, 2011

Python resource and extensions


Tutorials:
Installing:

http://webnewage.org/2009/06/23/what-is-pip
http://pypi.python.org/pypi/distribute#distribute-setup-py
http://pypi.python.org/pypi/pip
http://pypi.python.org/pypi/setuptools#files
http://www.komtet.ru/lib/plangs/python/easy-install-zagruzka-i-ustanovka-paketa
http://www.crummy.com/software/BeautifulSoup/#Download
http://peak.telecommunity.com/DevCenter/EasyInstall#installing-easy-install
http://stackoverflow.com/questions/1213690/what-is-the-most-compatible-way-to-install-python-modules-on-a-mac
http://stackoverflow.com/questions/452283/how-can-i-install-the-beautiful-soup-module-on-the-mac

Sources:

http://developer.berlios.de/softwaremap/trove_list.php?form_cat=76

Extensions:
http://pypi.python.org



1. C-Extension for Python: http://cython.org

Cython is a language that makes writing C extensions for the Python language as easy as Python itself. Cython is based on the well-known Pyrex, but supports more cutting edge functionality and optimizations.
The Cython language is very close to the Python language, but Cython additionally supports calling C functions and declaring C types on variables and class attributes. This allows the compiler to generate very efficient C code from Cython code.
This makes Cython the ideal language for wrapping external C libraries, and for fast C modules that speed up the execution of Python code.


2. Mathematics open source library: http://sagemath.org
3. http://www.pythonxy.com
4. http://www.enthought.com/products/epd.php
5. SciPy
6. PyCuda: http://mathema.tician.de/software/pycuda
7. Mrjob: https://github.com/Yelp/mrjob
    Run Hadoop Streaming jobs on Amazon Elastic MapReduce or your own Hadoop cluster
8. CRC: http://crcmod.sourceforge.net
9.Twisted: http://twistedmatrix.com/trac
     An event-driven networking engine written in Python
10. Requests: http://pypi.python.org/pypi/requests
11. MatplotLib: matplotlib.sourceforge.net, 
http://www.matplotlib.com
12. Py-LLVM: http://www.mdevan.org/llvm-py/index.html
13. Kalman filtering: http://www.scipy.org/Cookbook/KalmanFiltering
14. OpenGL: http://pyopengl.sourceforge.net
15. MapReduce on Python: http://me.lt/4xP7k
16.  Natural language toolkit http://www.nltk.org/download
17. Astronomy http://www.astropy.org

Open Source Python Tools for Classification (http://amundblog.blogspot.com)

  • Monte - less comprehensive than Orange, written purely in Python (i.e. noSWIGed C++). Looks interesting (has several classifiers algorithms), but the APIs seems to be in an early phase (relatively new tool in version 0.1.0)
  • libsvm - Python API for most popular open source implementation of SVM.Note: libsvm is also included with Orange and PyML. (I used this tools during my PhD a few years ago)
  • RPy - not exactly a classification tool, but it is quite useful with a statistics tool when you are doing classification (it has a nice plotting capability, not unlike matlabs), check out the demo.
  • PyML - also less comprehensive than Orange (specialized towards classification and regression, it supports SVM/SMO, ANN and Ridge Regression), but it has a nice API. Example of use: 
    from PyML import multi, svm, datafunc
    # read training data, last column has the class
    mydataset = datafunc.SparseDataSet('iris.data', labelsColumn = -1)
    myclassifier = multi.OneAgainstRest(svm.SVM())
    print "cross-validation results", myclassifier.cv(mydataset)
My recommendation is to either go with Orange or with PyML.

Catalogue:
http://www.java2s.com/Open-Source/Python/CatalogPython.htm
http://blogs.msdn.com/b/somasegar/archive/2011/08/29/python-tools-for-visual-studio.aspx

Sunday, April 4, 2010

Tuesday, March 30, 2010

IPython

Cool tutorial:
http://showmedo.com/videotutorials/series?name=CnluURUTV
http://showmedo.com/club/joinus?smdc=socb

http://onlamp.com/pub/a/python/2005/01/27/ipython.html

Features

Magic

IPython has several "magic" keywords:
%Exit, %Pprint, %Quit, %alias, %autocall, %autoindent, %automagic, %bookmark, %cd, %color_info, %colors, %config, %dhist, %dirs, %ed, %edit, %env, %hist, %logoff, %logon, %logstart, %logstate, %lsmagic, %macro, %magic, %p, %page, %pdb, %pdef, %pdoc, %pfile, %pinfo, %popd, %profile, %prun, %psource, %pushd, %pwd, %r, %rehash, %rehashx, %reset, %run, %runlog, %save, %sc, %sx, %system_verbose, %unalias, %who, %who_ls, %whos, %xmode

Tab Completion

A very powerful feature in IPython is tab completion. If you are familiar with Python, you may be thinking, The standard Python interactive shell has tab completion. All you have to do is:
[jjones@cerberus ~]$ /usr/local/python24/bin/python Python 2.4 (#2, Nov 30 2004, 09:22:54) [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import rlcompleter, readline >>> readline.parse_and_bind('tab: complete') >>> 
That's correct. Both the standard Python interpreter and IPython support "regular" completion as well as menu completion. To use completion, type a pattern you would like the shell to match, followed by the Tab key. When in "regular" completion mode (the default), the Tab key will:
  • expand the pattern to as many characters as it can while still honoring the original match criteria
  • list all items matching that pattern
For example:
In [1]: import os  In [2]: os.po os.popen   os.popen2  os.popen3  os.popen4  In [2]: os.popen

Python IDE

  1. http://eric-ide.python-projects.org/index.html
  2. http://netbeans.org (current release - Netbeans 6.7)
  3. http://wingware.com
  4. http://www.wxpython.org
  5. http://www.thekompany.com/products/blackadder
  6. http://www.uxpython.com/overview
  7. Komodo IDE
  8. Sublime Text 2
  9. Eclipse
  10. JetBrains PyCharm
  11. CodeBlocks
Others: http://www.awaretek.com/toolkits.html



Installing Python with Netbeans IDE:
  1. Netbeans is available from early access site: http://dlc.sun.com.edgesuite.net/netbeans -  there are dedicated releases for Python, Ruby, etc.
  2. Wiki: http://wiki.netbeans.org/Python
  3. Plugins:  http://plugins.netbeans.org/PluginPortal

PyGUI: a GUI API that is designed specifically for Python, taking advantage of Python's unique language features and working smoothly with Python's data types.

Tkinter: 
This default gui toolkit is installed when you install Python. It is mature, robust, and popular. You can be pretty sure that any user who has loaded Python can run any scripts you do using Tkinter. A very worthy toolkit; the standard bearer.

Easygui: 
Easygui is the easiest gui-creator known to man. It is based on the Tkinter toolkit and it uses the simplest, most intuitive syntax imaginable. Newbies should definitely try this out in order to get a sense of accomplishment. It is, however, mainly for use in obtaining data input from users and sending simple dialogs and other communication to the user. More complex requirements will require a more powerful toolset, but Easygui is still good for some useful and interesting tasks!

wxPython: 
wxPython is the "up and comer", the current challenger to Tkinter's throne. wxPython is a heavy-weight contender, with a great range of widgets that some find superior to Tkinter's. In addition, wxPython widgets have a more native look and feel on Windows than does Tkinter's widgets, since wxPython is built on top of wxWindows. On balance, wxPython is an excellent choice if you are using Windows. The tookit also works on Linux and Mac OS X, but is perhaps a bit more challenging to install than Tkinter.

PythonCard: 
My sentimental favorite, PythonCard is relatively new, but it is developing very quickly. PythonCard uses a "framework" model, based on wxPython, and seperates logic from presentation by using a "resource editor" file. PythonCard is very easy to learn and use, and it may be the ultimate gui-creator for Python someday. In the meantime, it is gaining in popularity and installation is easy and automatic on Windows. Installation on Linux and Mac OS X can be tricky for newbies, as you must install wxPython before you can install PythonCard.

Boa Constructor: 
A Gui Painter or Code Generator built on the wxPython toolkit, Boa Constructor development is still in Beta, but it ultimately offers the same kind of RAD, visual development tool as Visual Basic and Delphi, except it is also open source, free, and uses Python!

Wax: 
Wax is a GUI framework implemented as a layer on top of wxPython. Wax is a creation of Hans Nowak, noted Python hacker, and is intended to be simpler and easier to use than wxPython while maintaining wxPython's full power.

BlackAdder: 
A commercial GUI-Painter and IDE from theKompany, built on the Qt toolkit.. I have tried the hobbyist or home version, and it is really slick and inexpensive;, but you must have a good understanding of the underlying Qt toolkit to do any real work..

Anygui: 
is a unique project in that it allows you to create gui's by writing simple, python-type code that then automatically senses and uses whichever gui toolkit the user has installed on his machine, giving obvious advantages in universality. The syntax seems intuitive to me and easygui is being developed by an all-star caste of Famous Python Developers!

pyGtk: 
Based on the Gtk toolkit that underlies the Gnome environment for Linux and the GIMP, pyGtk is very powerful. There is a free gui painter available called pyGlade. pyGtk is great for use on Linux but is also good for Windows. pyGtk is powerful, professional grade stuff, but is not particularly easy.

Glade: 
a User Interface Builder for GTK+ and GNOME

Gazpacho:Next Generation GUI Design for GTK+ and GNOME
Jython: 
By using Jython, one gets easy access to the Java GUi libraries, SWING and AWT. In fact, using SWING or AWT is much easier using Jython than when using Java itself, because of the legendary ease of use of the Python syntax; however, you may have more difficulty porting your gui form the original environment in which you code it,m to another computer operating system than if you use Java. Still, it is portable, and relatively easy. I like playing around with Jython and SWIng, which is better than AWT. AWT however, has one advantage; it works on the Sharp Zaurus Linux based PDA, while SWING does not. Jython and SWING is a good choice of ruse on the Mac OS X., Linux, and also Windows.

HTML: 
Not a Python gui toolkit, but if you want to rub your Python code form a web browser using CGI, then creating a simple User Interface using HTML is the way to go.

FXPy: 
Uses the OpenGL toolkit and runs on just about any Unix and also on Windows.

pyFLTK: 
The Fast Light Toolkit is relatively easy for simple, lightweight guis. It runs on the openGL toolkit.

PythonWorks: 
A commercial gui-Painter and IDE, unfortunately discontinued by PythonWare. It was a first class product using the Tkinter toolkit. Unfortunately discontinued but see PythonWare's other fine products

TwiLight GUI
A GUI wrapper for wxPython, Tkinter, PyQT and PyGTK

Venster, a GUI Toolkit for Windows

Still more GUI toolkit options and information from the Python Wiki
Other GUI options:

vPython
is a really neat, easy to use toolkit for creating moving 3d graphics with Python. Highly recommended and fun to play around with!!!

PicoGui 
is a compact module for creating gui's on embedded systems and such small footprint devices. It runs on Linux and various PDA's, including the Sharp Zaurus.

IPython install


I have found the IPython command-shell particularly useful. It’s very well done, and has excellent documentation. Problem is, it doesn’t work so well on Mac OS X 10.5 Leopard. Your screen gets scrogged because of a Readline conflict (see the video). Here’s my cookbook for getting it to work – it’s way easier than all the other documents on the Internet lead you to believe.
  1. Installing IPython on Mac OS X is actually quite easy with the following command:
    sudo easy_install ipython
  2. Execute the command to load the right Readline library:
    sudo easy_install -f http://ipython.scipy.org/dist/ readline

Some references:

Powered by Blogger.