background preloader

Python

Facebook Twitter

Essential Tools for Pythonistas - projectb14ck. Pythonistas need a lot of good tools in order to work efficiently. I'd like to take a few minutes to enumerate some of my favorite tools that help me write better Python code faster. GitHub Although you're likely already using Github for hosting all of your projects (both open source, and closed source), if you aren't, you need to seriously reconsider what you are doing with your life. GitHub is an extremely useful platform for hosting Git projects. It provides lots of great tools for making your project easy to work on, easy to get assistance with, easy to discover, and tons of other things.

Vim + pyflakes Ok, so Vim may not be entirely necessary, but pyflakes definitely is. pyflakes is an awesome python project that integrates with Vim, and allows you to check for interpreter errors in your python code live (as you are coding). Furthermore, pyflakes is fast. Here's a little screen shot of pyflakes in action: Sphinx Writing good documentation is essential for good projects.

Read The Docs. Playing with PyPy. Common Mistakes as Python Web Developer. Written on Friday, December 24, 2010 A few weeks ago I had a heated discussion with a bunch of Python and Open Source people at a local meet-up about the way Python's path joining works. I was always pretty sure that people are aware of how the path joining works and why it works that way. However a bit of searching around on the internet quickly showed that it's actually a pretty common mistake to use the os.path.join function with arbitrary and unfiltered input, leading to security issues.

Because the most common case where user input comes from another system is web development I went a bit further and tried to find a few other cases where people might be blindly trusting an API or operating system. So here it is: my list of things not to do when doing Python web development. Untrusted Data and File Systems In PHP land this is common knowledge by now because many people write innocent looking code like this: <? The problem there is that you expect os.path.join never to go a folder up. Bringing Peace Through Programming. Continuing with the Python theme - If you're a developer, please click here to see how you can make money helping others. One of the guys on our Python discussion list wanted to know the difference between pass-by-value and pass-by-reference. Seeing how this same question has been asked a few time previously, I thought I would try and make a blog entry to give a simple explanation to demonstrate how it works. Some languages use pass-by-value, but Python on the other hand uses pass-by-reference.

What is the difference you ask? Well pass by value is exactly what it sounds like - you pass the value (a copy of everything in the memory). Python, OTOH passes by reference - instead of copying the list, a pointer to the list is passed, so when you see something like this: def do_something(a_list): a_list[2] = 4 mylist = [1,2,3,4] do_something(mylist) now mylist is: [1,2,4,4]. In call-by-value, the value of the arguments are copied into the function. Int a = 5 void func(int b) { b = 6; } func(a); Peewee, a lightweight Python ORM. October 08, 2012 09:25/7 comments/ peewee python Today I merged in the "unstable/2.0" branch of peewee. I'm very excited about the changes and I hope you will be, too.

I have written a documentation page on upgrading which gives the rationale behind the rewrite and some examples of the new querying API. Please feel free to take a look but much of the information presented in this post is lifted directly from the docs. Goals for the rewrite consistent: there is one way of doing thingsexpressive: things can be done that I never thought of What changed? The biggest changes between 1.0 and 2.0 are in the syntax used for constructing queries. I learned a valuable lesson: keep data in datastructures until the absolute last second. With the benefit of hindsight and experience, I decided to rewrite and unify the API a bit. I know some people don't care about lines of code, but I think its a good metric for complexity. Examples Since seeing is believing, I will show some side-by-side comparisons. Links. Latest News: Getting Started With Riak & Python.

Riak is one of a handful of non-relational datastores that has experienced some exposure lately, and with good reason. It's written in Erlang, is Dynamo-inspired and, while technically is a key-value store, functions very well in our experience as a document store (meaning you can store complex data as the value). Reading through the overview is highly recommended. It's also extremely predictable in production, handles node failures well and (here's the really interesting bit) demonstrates linear performance as you add nodes (see these benchmarks). This is impressive because many distributed systems, especially in the NoSQL space, don't behave like this. Like many other NoSQL options, it uses MapReduce for many types of queries (which you can write in either Javascript for ad hoc queries or Erlang for repetitious, speedy queries). But also of interest is that it provides an additional way to get at values in Riak Search, a Solr-like search component.

An excellent question. Django | The Web framework for perfectionists with deadlines. More Impressions of Python (from a Java developer) Jeff Bail has just written an article on his first impressions of Python. I've been teaching myself Python for the last two weeks as well and I generally share Jeff's impresssions. I just wanted to add some more. Compared to Java Python is not that different from Java. Generally it is said that Python is easy to learn. For Java developers it is probably even easier. It's not that different like a Lisp for example. Object-orientation Object-orientation seems a bit clumsy (a bit like JavaScript). Functional Programming Python supports functional programming. Django After reading a book about Python I wanted to actually use it in a simple web project with Django. Conclusion I haven't gotten really deep into Python by now, but my first impressions are generally very positive and I already feel comfortable with it.

Pyjamas - Python Javascript Compiler, Desktop Widget Set and RIA Web Framework. Python Webkit DOM Bindings. The Python Webkit DOM Project makes python a full peer of javascript when it comes to accessing and manipulating the full features available to Webkit, such as HTML5. Everything that can be done with javascript, such as getElementsbyTagName and appendChild, event callbacks through onclick, timeout callbacks through window.setTimeout, and even AJAX using XMLHttpRequest, can also be done from python.

Why is this important - why is it a "big deal"? Browser engines are amongst the most powerful GUI engines available, with the world's top software organisations and corporations focussing a lot of effort into competing to be "the best". This competition results in some incredibly exciting developments... that are then restricted to being exclusively used from one of the world's most awkward and obtuse programming languages: javascript. So the real question is: why should this state of affairs be tolerated? Python is a fast-growing language that is highly compact, powerful and elegant.

Status. Sahil Lavingia - Reworder – A tale of learning Python and launching an app in five days. Introduction to Pyjamas, Part 1: Exploit the synergy of GWT and Python. Introduction Google's Web Toolkit (GWT) lets you develop a Rich Internet Application (RIA) with Ajax, entirely in Java™ code. You can use the rich Java toolset (IDEs, refactoring, code completion, debuggers, and so on) to develop applications that can be deployed on all major Web browsers. With GWT you can write applications that behave like desktop applications but run in the browser. Pyjamas, a GWT port, is a tool and framework for developing Ajax applications in Python. Pyjamas contains a stand-alone Python-to-JavaScript compiler, and an Ajax framework and widget set. Using these components, you can write comprehensive applications without writing a single line of JavaScript.

This article explains the background, rationale, related tools, and benefits of Pyjamas while showing you how to create a sample application that will store basic contact information (name, e-mail address, telephone number). Part two in this series will explain how to build custom Pyjamas components. Back to top #! 10 Reasons Python Rocks for Research — Hoyt Koepke. The following is an account of my own experience with Python. Because that experience has been so positive, it is an unabashed attempt to promote the use of Python for general scientific research and development.

About four years ago, I dropped MATLAB in favor of Python as my primary language for coding research projects. This article is a personal account of how rewarding I have found that experience. As I describe in the next sections, the variety and quality of Python’s features has spoiled me. To clarify, I am not advocating just Python as the perfect scientific programming environment; I am advocating Python plus a handful of mature 3rd-party open source libraries, namely Numpy/Scipy for numerical operations, Cython for low-level optimization, IPython for interactive work, and MatPlotLib for plotting.

Holistic Language Design I once believed that the perfect language for research was one that allowed concise and direct translation from notepad scribblings to code. Readability gives. Rich Internet Applications (RIA) » Blog Archive » Slimmed Down Software- A Lean, Groovy Approach Part 5- Deliver Fast. This article originally appeared in the August 2010 edition of GroovyMag, the Groovy and Grails magazine. Parts 6 and 7 are currently available for download from the magazine’s site, and more will come each month. Previous articles in this series are on the Canoo website: Part 1: Eliminate Waste, Part 2: Build Quality In, Part 3: Create Knowledge, and Part 4: Defer Commitment.

Lastly, if you like this, you may want to check out some of my older blog posts from my personal site under the ‘craft’ category. Enjoy! The Groovy Programming Language advertises itself as an “agile and dynamic Language for the JVM”, but what does this mean exactly? About this series Groovy is an agile programming language. Some of the code examples are basic while others are advanced. Lean Revisited Part 1 of this series contained a more in-depth explanation of Lean, and I won’t repeat it here. Principle 5 – Deliver Fast The easiest way to deliver quickly is to deliver less.

Sidebar: Little’s Law and throughput. Viewing Python 3.2 as the successor to Python 2.7. Over on python-dev a discussion kicked up over what to do about backward-incompatible changes against Python 2.7 in the name of fixing consistency. The suggestion seemed to be for a Python 2.8, but that is simply not going to happen. I think the reason the idea of Python 2.8 even came up is because I don't think people in general realize how python-dev views the latest and upcoming releases of Python, so I just wanted to clarify this point for the general community.

For as long as I have been involved in Python's development (joined python-dev in June 2002), there has always been a maintenance version and an in-development version. When a version of Python is released it immediately becomes the maintenance version. This is exactly the same for Python 2.7/3.2 from the perspective of python-dev. Which is why the concept of a Python 2.8 coming from python-dev will never happen.

Yes I said "fork"; that "dirty" four letter word that starts with "F" and ends in "K". Using the Cython Compiler to write fast Python code. Passionate Python developer since 2002after Basic, Logo, Pascal, Prolog, Scheme, Java, C, ...CS studies in Germany, Ireland, FrancePhD in distributed systems in 2007Language design for self-organising systemsDarmstadt University of Technologies, GermanyCurrent occupations:Employed by Senacor Technologies AG, GermanyIT transformations, SOA design, Java-Development, ...»lxml« OpenSource XML toolkit for Part 1: Intro to CythonPart 2: Building Cython modulesPart 3: Writing fast codePart 4: Talking to other extensions Cython is the missing linkbetween the simplicity of Pythonand the speed of C / C++ / Fortran.

Cython is the missing linkbetween the simplicity of Pythonand the speed of C / C++ / Fortran. Cython is an Open-Source projecta Python compiler (almost)an enhanced, optimising fork of Pyrexan extended Python language forwriting fast Python extension modulesinterfacing Python with C libraries ... the fastest way to port Python 2 code to Py3 ;-) PyBrain. The Complete Guide to Setting up Python Development Environment on Windows. (Originally adapted and updated from Tom Willis’s posts here and here). Also, as commenters suggested, you should take a look at ActiveState which can probably save you all this trouble… Setting up Python for development on a Windows environment turns out to be not such an easy task.

After setting up several such environments and running into all sort of problems I had to figure out I decided it would probably be worthwhile for myself and other developers to document the process… If you’re starting Python development on Windows, and especially if you’re using Google App Engine (as this guide is about Python 2.5.4) this guide is for you… Install the Python Runtime The first step in setting up a Python development environment is to install the Python runtime. You can find a list of all the Python releases here. Just download the msi that fits your system and install it. Set up your Environment Setting the PYTHON_HOME Environment Variable Setting up the PATH variable Installing easy_install. Teaching a Neural Network to Learn the Letter A from B.

I’m going to make the assumption that if you are reading this you already know what a NN is, and you are trying to do some sort of image recognition. I’m also going to assume you are somewhat familiar with programming preferably in Python since that’s what all the examples will be using. To get started we are going to need the following, A neural network implementation A imaging library to read images Sample images to train and test on. The images we are going to use are the following, The Letter A The Letter B Our goal is to teach a neural network to tell the difference between the above. The first is the easiest to code so I am going to go with that.

The next step is to write some code which takes the above pixel data and feeds it into the Neural Network. import bpnn import Loader if __name__ == '__main__': cla = Loader.Loader() hiddennodes = 2 adata = cla.loadimagedata(". You can see that in the above we create a loader object which allows us to read images and networks. This is much better! Python for Fun. This collection is a presentation of several small Python programs. They are aimed at intermediate programmers; people who have studied Python and are fairly comfortable with basic recursion and object oriented techniques.

Each program is very short, never more than a couple of pages and accompanied with a write-up. I have found Python to be an excellent language to express algorithms clearly. Some of the ideas here originated in other programs in other languages. But in most cases I developed code from scratch from just an outline of an idea. However Lisp in Python was almost a translation exercise from John McCarthy's original Evalquote in Lisp. From many years of programming these are some of my favorite programs. Chris Meyers.