Home > Google App Engine, Programming, Python > Setting Up Aptana for Python Coding

Setting Up Aptana for Python Coding

As programmers we always need to keep in mind that our code will have to be read by other programmers (and us) in a later time. This means that instead of just focusing only on coding something that works, we have to be able to make it readable and maintainable. Some of my thoughts about this have been covered on a previous post, so now we will focus on how we can use Aptana to help us in this task, after going through some general tips on how to write more readable code in Python

Before we begin I feel I should first note that “beautiful” code isn’t always efficient code. After writing a fairly readable code base then it’s the time to see if some chunks can be optimized, and if this leads to a somewhat obscure code, then it’s the time to use in-line comments that explain what does it do and why has it turn so “ugly” (if you read my previous post, you’ll see that I believe that this type of comments, I believe shouldn’t exist in anyone’s code, since the code itself should be self-explanatory, but I guess this is one acceptable exception). Also, I will not cover writing idiomatic code for Python, since this depends on how “advanced” your team is on Python and this is supposed to be a catch-all guide.

Style Guide

Luckily for us the guys at Python have written an excellent guides (PEP8 for code and PEP247 for docstrings). I suggest having a read at them, but we will see some important points below.


Use 4 spaces per indentation level and never mix spaces with tabs.

Line Width

Use up to 79 characters per line. If you ever have to use an old laptop to do your job you will be thankful about this. Also if you are using a big 27″ monitor, you will be able to have readable tabs next to each other, avoiding the useless whitespace caused by a few extra long lines. You can split long lines by using parentheses, brackets and braces taking advantage of Python’s implied line continuation. A backslash can also be used when implicit continuation is not applicable.

Line Spacing

For top level functions and class declarations one line should be used. For methods inside a function two lines. Single blank lines can also be used inside a function to separate logical sections.

Expressions and Statements

No spaces immediately inside parentheses, brackets or braces.No spaces immediately before a comma, semicolon or colon.
No spaces immediately before open parentheses, brackets or braces.
Use one space (only) around comparison operators.No spaces around = when used to indicate a keyword argument or a default parameter value.
Avoid multiple statements in one line.


Modules: lowercase
Packages: lowercase
Class: CamelCase
Exceptions: CamelCase ending with Error
Global Variables: lower_case
Functions: lower_case
Functions and Methods Arguments: lower_case
, using self as first argument for instance methods and cls for class methods
Method Names and Instance Variables: lower_case, _lower_case for non-public
Constants: UPPER_CASE

Setting Up Aptana

First of all make sure that pythonNature and PyDev Builder are selected on Project Natures on the project’s properties.

Screen Shot 2013-08-03 at 1.07.52 AM

Screen Shot 2013-08-03 at 1.08.31 AM

Screen Shot 2013-08-01 at 8.33.58 PM

Spaces, Indentation and print margin column (visual aid for the 80 characters per line limit)

Screen Shot 2013-08-01 at 8.30.08 PM



Screen Shot 2013-08-01 at 8.35.40 PM


Screen Shot 2013-08-01 at 8.35.55 PM

Code Folding

Screen Shot 2013-08-01 at 8.35.25 PM

Code Analysis
1. PyDev

Screen Shot 2013-08-01 at 8.34.37 PM

Screen Shot 2013-08-01 at 8.34.44 PM

Screen Shot 2013-08-01 at 8.34.48 PM

Screen Shot 2013-08-01 at 8.34.54 PM

Screen Shot 2013-08-01 at 8.35.02 PM

Screen Shot 2013-08-01 at 8.35.08 PM

2. PyLint

Screen Shot 2013-08-01 at 8.39.04 PM

Keep in mind that in both PyDev and PyLint I have deactivated specific errors that kept my Problems tab cleaner for the current state of the project. They are not meant to be part of the guide. You will have to decide if you want to disable specific warnings depending on your project
Bonus (Indentation Guides)

In order to have indentation guides to your workspace you must install the PDT tools Indent Guide plugin from here

Screen Shot 2013-08-01 at 8.31.24 PM



Categories: Google App Engine, Programming, Python Tags:
  1. No comments yet.
  1. No trackbacks yet.

%d bloggers like this: