How to Write and append to zip archives in Python

Writing and appending to zip archives dynamically using Python is our need to manage the space on server. In my previous article you have seen how to read zip archives in Python. Now we are concentrating on How to Write and append to existing zip archives using Python.

We will take the same zip files for our example on reading zip files, I suggest you go back and give it a quick look. The two files we will be using are: “file1.txt” and “file2.txt”.

If you just want a new zip file with your files in it, then it’s a matter of a few lines using the zipfile module. First, create the archive in write mode:

Then start adding files:

That’s essentially it. The zipfile module handles all the details of opening and reading the files, compressing them and inserting them into the archive. Don’t believe me? Then let’s take a look. First we close the file, then reopen it in read mode.

The printdir() method of a zipfile works just like the function we wrote in the last article to print out the files in the archive. You can also check that the files contain the data we expect:

But what if we want to add files to an existing zip? It’s simple enough, we just need to open the file in append mode. Opening an existing zip file in write mode will erase the zip, so be careful when you’re using that mode.

Let’s say theres a “file3.txt” with the following contents:

We add it to the zip we just made ( with the following code:

Finally, you can write a program to extract zip files to disk in just a few lines. The following Python program extracts all zip files given as arguments to the current directory.

In action, it looks like this:

Be careful, this simple program will only work if the zip archive has a flat file structure, i.e. it contains no nested directories. If it does, you’ll need to adjust the program to create the directories as it goes, but I’ll leave that extension up to you.

Leave me a comment and let me hear your opinion. If you’ve got any thoughts, comments or suggestions for things we could add, leave a comment! Also please Subscribe to our RSS for latest tips, tricks and examples on cutting edge stuff.

How to read zip archives in Python

You must have run under space issues when Zip is the name of a popular file compression algorithm, which lets you both combine multiple files into a single archive and store them on disk using less space. We’ll show you how you can open and read zip files in your Python scripts.

kijiji canada goose mystique, Canada Goose Jacket, Canada Goose Jackets, Canada Goose Outlet,canada goose outlet berry chilliwack bomber., Canada Goose coats, Canada Goose, Canada Goose Outlet

Python’s “batteries included” philosophy regarding libraries is well known. What it means to you is that the functions that perform the majority of basic operations you’ll need in your scripts are included in the standard library that comes with the Python distribution. Working with zip archives is no exception — functionality is included in the zipfile module.

If you’re going to be working more than just casually with zip archives, you won’t get too far without knowing the specifics of how files are arranged within archives. The best resource for this is the ZIP Application Note distributed by PKWARE, the company responsible for developing the compression algorithm. The application note contains a full file format specification for .zip archives.

For this article we’ll be working with a zip file called “” which contains two files: “file1.txt” and “file2.txt”. If you’re following along, you can download the file here.

First things first, we need to load the file and create a ZipFile instance:

NB: It’s important that if you modify a zip file, you always close the archive. Even though we won’t be changing the file in this article, closing the archive is a good habit to be in. The following code will close a ZipFile:

Now that we’ve got a ZipFile, what can we do with it? If all you need is to pull out the contents of the archive, then you can use the read method:

There are two classes defined by the module you must use to read zip archives. The first, ZipFile, we’ve already dealt with. ZipFile deals with methods relating to the archive as a whole: opening and closing the archive, reading and writing from it and the list of files contained.

We’ve demonstrated opening, closing and reading from archives already — we’ll leave writing for another day. Let’s take a look at accessing the file list. The following is a short python script that accepts a number of zip archive names as arguments and then prints the contents:

When we run it with our test archive as a parameter:

The important function here is the namelist function, which simply returns the filenames of the contents of the archives. You can combine this with read to dump the full contents of the archive to screen:

The second class defined by the zipfile module is ZipInfo, and are used to store information about each single file contained within the archive. If you need more information about the archive’s contents than just the filenames then you need to inspect the ZipInfo file.

You can get an info file for any member by using the ZipFile.getinfo(name) method, or if you want the whole list, you can use the ZipFile.infolist() method. The following program prints the name, size and last modification time of each file in the archives given as command line arguments:

Then when we run the program:

In Python, working with zip files is as easy as that. Building zip functionality into your own scripts allows you to access and store resources while using reduced disk space.

Leave me a comment and let me hear your opinion. If you’ve got any thoughts, comments or suggestions for things we could add, leave a comment! Also please Subscribe to our RSS for latest tips, tricks and examples on cutting edge stuff.

Freeform GUIs in Python: Tkinter canvas

The Tkinter framework provides some standard GUI widgets for use in building Graphical User Interfaces in Python. If you need more freedom you can use the Canvas widget included in Tkinter, which gives you an area where you can draw custom shapes.

canada goose parka expedition femme, Canada Goose coats, Canada Goose sale, Canada Goose Factory Outlet,canada goose mens tundra., Canada Goose Outlet, Canada Goose, Canada Goose

We’ll start with a basic Tk application. This will create a window containing a Canvas widget 300 pixels by 300. Note: you can type all the commands in this article into your interpreter, and the GUI window will be updated as you go.

The resulting application doesn’t look like much, you should have a square, grey window. More interesting is to draw shapes to the canvas — the follow code, using the create_rectangle method of the canvas, draws a green square to the top-left corner:

create_rectangle takes four positional arguments representing the top-left and bottom-right coordinates of the rectange, and then a list of optional named parameters. In this case we set the fill colour to green. For a full list, you can browse the documentation for Tkinter rectangles here.

Likewise, you can draw other shapes to the canvas. The create_oval canvas method works in the same way as the create_rectangle method, except that it draws the ellipse contained within the bounding rectangle. The following line draws a blue circle directly below the square:

The next basic shape type to learn is the polygon, which allows you to draw objects of any shape. The create_polygon method takes in any number of positions and draws the shape that is formed by using all the positions as vertices. The following example draws a red diamond to the right of the square:

Polygons could have any amount of points, so you could have just as easily drawn a five, six or seven sided shape here, rather than a diamond.

Lastly you can add text to the canvas by using the create_text method. This method takes the centre point of the text object, then optional arguments including the colour. The most important of these arguments is text which is the text to be written to the canvas. In the following example we write some simple text to the bottom-right corner of the window:

We also manually set the font, to make the text appear larger. At their simplest, font’s are simply a tuple containing a font name and size — in this case, 16 point Helvectica.

Deleting items from the canvas

You may have noticed that we’ve been storing the value returned by the create methods used to add shapes to the canvas. Each creation method returns an object indentifier, which allows us to manipulate the objects after they have been added.

You can delete any item from the canvas by using canvas.delete:

By adding and removing items from the canvas, you can create more sophisticated and customised feedback to users of your applications. The canvas is highly customisable and allows more complicated interactions with objects.

Leave me a comment and let me hear your opinion. If you’ve got any thoughts, comments or suggestions for things we could add, leave a comment! Also please Subscribe to our RSS for latest tips, tricks and examples on cutting edge stuff.

Treat Google as an application platform

canada goose sale bloomingdales, Canada Goose, Canada Goose outlet,canada goose kensington parka for sale, Canada Goose jackets, Canada Goose Online,canada goose sale at simons., Canada Goose Black Friday, Canada Goose Jackets

Good news for developers as we can treat Google as an application platform. SMB (Small medium business) are trying to harness Google platform and applications as much as possible. Now, you can build your application on excellent architecture such as Google’s. I am sure Google Apps and Google App Engine will rock in development community. These applications can help with set of applications and development platform for building your own applications. Following is my quick review on Google’s offerings

Google Apps

Google Apps provides a suite of online applications, which include the following:

  • Gmail provides address book and search features, along with integration with Google Talk and Calendar.
  • Google Talk is an instant messaging tool for real-time communication with contacts. File sharing and voice is included as well.
  • Google Calendar organizes schedules with easy-to-use calendars that may be shared among groups of people. In addition, you may integrate it with your current calendar platform.
  • Google Docs allows you to create documents, spreadsheets, and presentations. It supports familiar document formats such as the Microsoft Office Suite of products, so you can easily use it with existing systems. Google Docs also provides real-time collaboration with other users.
  • Start Page provides you with your own start page to customize to include the tools such as email, calendar, or another website.
  • Google Sites provides a website on which users may work together to build and edit Web applications. It brings together all the power of Google. You may embed videos, straight HTML, Google Gadgets, a spreadsheet from Google Docs, and so forth; it is only limited by the user’s imagination. It also provides a central place to collaborate. The term wiki comes to mind when I work with Google Sites.

The Google Apps initiative is a powerful alternative to more established products such as SharePoint and Lotus Notes. A great selling point is that Google provides the entire behind-the-scenes infrastructure to run everything, and it stores the data (although you can choose to store data locally). Plus, everything runs within the browser window, so there is no need to install anything additional on user computers.

Small business can get up and running with Google Apps in no time and at no cost. The Standard Edition offers all of the previously discussed applications for all of your users. The Premier Edition comes with a US$50 per user fee. It provides everything in the Standard Edition, along with more tools for enterprise usage. This includes APIs for integrating with existing systems, policy management, more storage space, and customer support. In addition, an Education Edition is available for students.

My initial feeling is that Google Apps is a great offering, especially for small businesses without the capital to build such an infrastructure. Also, the push towards a mobile, disconnected workforce lends itself well to such an offering. I recommend checking out Google Apps: The Missing Manual , which offers in-depth information on every facet of the product.

At this point, Google Apps covers pretty much everything a group or company would need except for custom applications, and Google has an answer for that too.

Google App Engine

If the Google Apps paradigm is attractive, but it does not offer the applications you need, you can use the Google App Engine to build and deploy a custom application via Google-provided infrastructure. The Google App Engine gives developers access to Google’s platform with the following features:

  • The Google App Engine SDK for building applications locally and then deploying to the Google App Engine platform;
  • A scalable server infrastructure;
  • Support for multiple languages, although Python is the only language supported at this time;
  • A robust data store via Bigtable, which is a distributed storage system that Google uses for dealing with its vast amount of data. It is designed to scale to a very large size, so it can easily accommodate your data;
  • A Web command console that allows you to manage your application.

The Google App Engine includes several APIs for leveraging Google functionality. This initially includes APIs for working with user accounts; Mail API for working with mail items; and other APIs for working with the data store and so forth. The Google App Engine integrates with all versions of Google Apps, so custom applications for teams can be built and deployed via the Google platform.

Unfortunately, the only supported language is Python, which is not a surprise considering it’s no secret that Google uses Python quite a bit internally. While that is great for the Python community, it leaves many developers waiting for more and not wanting to learn another language. As a developer, it is intriguing to get a taste of how a very successful organisation such as Google does things with features such as Bigtable and the Google file system.

World domination in Google’s Mind .. isn’t it?

Many Microsoft haters applaud Google Apps and the Google App Engine. While I find it hard to believe Google Docs will force Microsoft Office off of its high perch, it does make me wonder about another behemoth rising in the industry. Like Microsoft, the tenets of Google are reaching into every imaginable space. Is its next target the operating system? Do we want one company controlling everything? It is good to have companies battling against each other because the consumer winds up being the winner.

Are you currently using Google Apps or the Google App Engine? If not, do you plan to use either product in the future? Leave me a comment and let me hear your opinion. If you’ve got any thoughts, comments or suggestions for things we could add, leave a comment! Also please Subscribe to our RSS for latest tips, tricks and examples on cutting edge stuff.

Python Web Scrapper with BeautifulSoup

You must have wondered how people are showing data which you might have already looked on few other sites. Well, they have scrapped the data from the source and manipulated that within their own application.

There are thousands of HTML (or SGML, or XML) parsing libraries for hundreds of languages out there, but we will use a Python library called BeautifulSoup which takes care of almost all of the work for you. The BeautifulSoup library is an extremely helpful tool to have at your disposal, since it not only gives you functions to search and modify your parse tree, but it also handles the broken and malformed HTML you’re likely to encounter on an average Web page.

You can download the library at its Web page. It also resides in some popular software repositories, such as the apt-get repository used in the Debian and Ubuntu distributions.

We’ll write a Web scraper that prints all the displayed text contained within <p> tags. This is a very simple implementation that is easy to trip up, but it should be enough to demonstrate how using the library works.

First up, we need to retrieve the source of the page that we want to scrape. The following code will take an address given on the command line and put the contents into the variable html:

Then we need to build a parse tree using BeautifulSoup:

At this point the code has already been cleaned up and converted to unicode by the BeautifulSoup library, you can print soup.prettify() to get a clean dump of the source code.

Instead, what we want is to print all of the text, without the tags, so we need to find out which parts of the parse tree are text. In BeautifulSoup there are two kinds of nodes in the parse tree, plain text is represented by the NavigableString class, whereas Tags hold mark-up. Tags are recursive structures, they can hold many children, each being either other Tags or NavigableStrings.

We want to write a recursive function that takes part of the tree: if it is a NavigableString print it out, otherwise, runs the function again on each subtree. Because we can iterate over a tag’s children simply by referring to that tag this is easy.

Then we just need to run that function on all the <p> tags. We can use BeautifulSoup’s in built parse tree searching functions to retrieve all of them:

That’s it. You’ve got a fully functioning, if basic, HTML scraper. For more help with searching the parse tree, look up the BeautifulSoup documentation.

The full code for this example is as follows:

Leave me a comment and let me hear your opinion. If you’ve got any thoughts, comments or suggestions for things we could add, leave a comment! Also please Subscribe to our RSS for latest tips, tricks and examples on cutting edge stuff.

Pyjamas (Python GWT) – Introduction and Creating Widgets

If you are a Python developer and don’t like JS a lot then look at Pyjamas desktop it will run on Web as well as desktop applications. It’s based on google webkit, pyjamas is a cross-browser web application development API. it looks like a desktop API, but underneath, pyjamas is an AJAX library and a comprehensive widget set (implemented as AJAX but you never go anywhere near JavaScript, because at the core of pyjamas is a python-to-javascript compiler).

What is Pyjamas desktop?

It is a cross-platform application development API. like pygtk2, like python-qt4 and wxWidgets, is very powerful as you can do the followings:

  • load complete html pages
  • complete stylesheets
  • even execute bits of javascript

So, how you can do it? answer is pretty simple because it’s based on webkit. so you get access to the DOM model, you get full HTML compliance, wickedly-fast javascript execution, media plugins, CSS stylesheets – everything.

You should have exposure of developing a 10 line “Loader” HTML page and an optional CSS, thats cool isn’t it?. Even the CSS file is optional because you are provided via the Pyjamas API with access to some of the more useful CSS features such as setting the width and height, and you can if you wish to directly manipulate the CSS style properties from your application.

in short, you get to write apps that look like they ought to be running on a desktop, and pyjamas takes care of all the nasty browser tricks that you would normally perform in order to make it cross browser compatible for safari, opera, IE7, IE6, firefox, mozilla, midori etc.

Lets take a Hello World Example

Now, lets look at Pyjamas Desktop Widgets

An important part of a widget toolkit is being able to write your own widgets. In many widget sets, you are confronted immediately with a quite complex set of unusual-looking functions – paint, draw, refresh and other manipulations. Pyjamas has none of that: in both Pyjamas and Pyjamas-Desktop you’re manipulating the DOM model – an HTML page – as if it was an XML document. Pyjamas provides a module which makes the job of controlling the underlying DOM model that much easier, and this tutorial shows step-by-step how to go about creating your own widget.

Vertical Slider

We start off by importing the DOM model and, because the slider will receive mouse (and later keyboard) events, we base it on FocusWidget. FocusWidget has the means to add keyboard and event listeners, set a “tab order” index, and to set and clear focus:

So, we derive our class from FocusWidget. We don’t declare a width and height as parameters, because Pyjamas Widgets are based on HTML principles: DOM models. So, you either set the CSS “Class” with setStyleName(), or you use the Pyjamas Widget functions setWidth() and setHeight(). We do however want to pass in the slider’s minimum, maximum and default values, and we may also want to keep track of who might be interested to know that the slider’s value has changed.

Here also is the first actual bit of underlying HTML / DOM model showing through: we’re basing the widget on a “div” tag, hence we call DOM.createDiv() and set that as the FocusWidget’s element. (Immediately, therefore, you can see that the Pyjamas Widgets are effectively… “guardian” classes that look after and manipulate bits of the underlying DOM model, making the whole process of creating and maintaining your application just that little bit easier to understand). We’re also going to copy what AbsolutePanel.__init__() does, making the container DIV free-moving, and we’re also going to throw in a second hard-coded “div” for the actual slider handle:

Then, as this is just a demonstration, we’re going to hand-code the slider handle with some attributes, making it 10 pixels high, a border of 1 pixel, fixing it to be the same width as the Widget, and making it a grey colour. A much better way to do this would be to set a CSS stylesheet where people could over-ride all these settings. Note that we don’t use DOM.setAttribute() to set the border, width and height. You should consult HTML specifications: you will find that “border” is an attribute for DOM tags such as “table”. So, if you try to call DOM.setAttribute() on a DIV tag, you’ll find that it silently fails in the browser – or if you remember, and examine the Javascript Console, you might be lucky and find a warning. However, if you try the same thing under Pyjamas-Desktop you will be rewarded with a much more useful run-time error. The upshot is: pay attention to the underlying DOM model, and remember to simultaneously develop your app using both Pyjamas and Pyjamas-Desktop, to save yourself a great deal of time. If you want to set a border on a “div” tag, you must set it as a CSS Style attribute:


With the basic beginnings, it’s enough to test out, to see if we have it working. If all we wanted was a little grey box in our widget, we’d be entirely done.

One thing I love about Pyjamas: this is enough code to do exactly what you want: create our slider, add it to the root panel, set its width to 20 pixels and the height to 100. Couldn’t get any easier. A quick run of this code shows that yes, indeed, we have a little grey box, which is very exciting. Next on the list is to make it move, and for that, we’ll add a “click listener”.

Making it move

To receive a click event, we use FocusWidget.addClickListener(). We’re going to make the widget itself receive the mouse click event. Looking at FocusWidget.onBrowserEvent(), we can see that we must add a function called onClick() to our VerticalDemoSlider. As we want to know where the mouse was clicked, we will need to add two arguments to the onClick() function, in order to receive the mouse event object as the second. Then, we simply take the mouse event y position, the absolute location of the container, and the “offset height” of the widget, do a little math and, copying some lines of code from AbsolutePanel.setWidgetPosition, we can change the location of the slider handle:

Okay – let’s test it! Save, run… lights, camera, action, aaand… nothing. huh. What have we done wrong? Oh yes, we forgot a very important line. Go back to VerticalDemoSlider.__init__ and add this, at the end, and try again:

Amazing! We have a slider widget! A single-click moves the slider to where you clicked the mouse. Notice how the slider centre moves to where your mouse pointer actually points to: this is entirely a fluke, and is probably due to bugs in the CSS style implementation of your browser. Notice also that we haven’t actually set the value of the “slider”, but there’s enough maths to calculate it. We can add these extra lines on to the end of moveSlider():

Then, we also add a setValue() function, which not only records the new value but also notifies any listeners. Copying the style of Label and other widgets’ addClickListener() and removeClickListener() functions, we’re doing addControlValueListener() and removeControlValueListener() to match.

Now we should really see if that works. In the “test code”, add these extra lines to ControlDemo.onModuleLoad() and also add the additional function onControlValueChanged:

Leave me a comment and let me hear your opinion. If you’ve got any thoughts, comments or suggestions for things we could add, leave a comment! Also please Subscribe to our RSS for latest tips, tricks and examples on cutting edge stuff.

PHP vs Python: Analysis

PHP vs Python – What does it take to state one language better than other? One answer can be flexibility, development friendly, licensing policy (open source or commercial), community,  portability, dynamic typing, support for variable number of function arguments and ability to freeze live objects in a string representation. Documentation of course is a major player when you choose a language because you still have to sharpen your skill and you haven’t worked on that particular language yet.

Features which supports PHP

  • syntax very close to C and Perl, with curly braces and dollar signs
  • the ‘switch’ statement and ‘do … while’ construct just like C
  • increment and decrement and assignment operators
  • the ternary operator/statement (… ? … : …)
  • schizophrenic tableau of function names. There are no namespaces, so functions often have prefixes to denote their source (but often not). Functions are often placed into classes to simulate namespaces.
  • a very casual language, where globals are often used to pass arguments (global variables should not be used, that is language independent)
  • commonly installed environment
  • aliases (‘$a =& $b’ means that when $b changes, $a changes also) (should be “references”, not “aliases”, but are called aliases)
  • one array type that doubles as a list and a dictionary. Dictionary keys are iterated in their original order.
  • Excellent Documentation
  • Huge Community base with huge supportive codebase available online

Features which supports Python

  • namespaces and modules
  • small core
  • indentation to mark out block structure rather than curly braces, which make code look prettier
  • clear, concise, and orthogonal syntax
  • self documenting with docstrings and pydoc (PHP 5 has reflection and doc strings)
  • keyword arguments to functions and methods, easy support for default arguments
  • true object orientation and ‘first class’ classes and functions
  • classes are used extensively in the standard library
  • multiple inheritance
  • object-oriented file handling
  • method chaining
  • everything is a reference
  • ‘del’ statement for all data types
  • consistent case sensitivity (PHP does for variables, but not functions) (Functions are case insensitive)
  • simple array slicing syntax
  • iterators (PHP 5)
  • structured exception handling (PHP 5)
  • operator overloading
  • threading
  • lots of high-level data types (lists, tuples, dicts, mx.DateTimes, NumPy arrays, etc.)
  • dates that aren’t limited to UNIX timestamps (<1970, >2038)
  • support for all major GUI frameworks
  • strong internationalization and UNICODE support
  • maturity, stability and upward-compatibility
  • tends to lead to much more scalable applications

Unlike PHP, which has web development features built directly into the core language, Python’s web development capabilites are provided by add-on modules. Basic CGI capabilities are provided by the ‘cgi’ module which comes in Python’s standard library. There’s also a wide range of third-party modules available for Python; some are complementary, others compete. As a result, Python provides a more flexible base for web development.

There are some adverse side effects of this flexibility. First, the range of choices can be bewildering. Unless you are working experienced Python web developers, PHP is easier to get started with. Second, support for PHP is more common with shared-hosting companies than support for the various Python options.

Another difference is that PHP is embedded in the web server, whereas Python web applications can either be embedded in the web server like PHP or run in a separate process.

Now, lets test how fast they execute to find all the prime numbers under 10000. We will execute the test three times by optimizing the outcome

$ time ./script.php
Language Script 1 Script 2 Script 3
PHP 1.359 1.753 1.191
Python 1.894 1.636 1.634

Well, this shows that PHP runs faster than Python but here is a catch. PHP can run faster for smaller codes but when we talk in terms of scalable large system then Python will perform better. The above code was small where we were finding all prime numbers under 10000 and PHP shows why its choosen in most of the small web applications. No doubts there are few big names with PHP backing too.

Lets do one more analysis where mathematical calculations are performed

Sample script loops through a FOR statement 2,000,000 times calculating the MD5 hash of N + N, N equaling the number of passes thus far.


Round 1 – 2,000,000 Passes
PHP = 21.4227 sec
Python = 9.8737 sec

Round 2 – 2,000,000 Passes
PHP = 21.1122 sec
Python = 9.7241 sec

Round 3 – 1,000,000 Passes
PHP = 9.811 sec
Python = 4.429 sec

Round 4 – 1,000,000 Passes
PHP = 9.857 sec
Python = 4.280 sec

As you can see, Python is more than 2 times faster than PHP in performing this operation, which is more towards executing a mathematical algorithm.

Another Opinion – Python has been optimized for mathematical algorithms so in that respect it will blow PHP out of the water but if you compare which language can server more web pages in a period of time you find that PHP is noticeably faster.

Other important Aspects which make a language preferable are listed below:

Speed of Execution

Given a fairly intense problem neither language has a large advantage over the other, and each will be better for different things. We can thus rule out execution speed for 99% of what we do.

Speed of Writing

Assuming the languages in question all run at an acceptable speed (and they probably do) this becomes the second most important metric (number 1 being if they will actually run). I must be honest here and say that I have not used Python long enough to be sure how fast or slow I am for developing in it but I can say that so far it seems faster.


I may have not been using Python long but I can hands down say that it’s easier to maintain. I indent stuff in PHP anyway but the lack of curly braces is really nice and I prefer the scope access of Python over PHP ( vs $object->property) but I think that’s a matter of personal opinion that you need to decide on for yourself.

Ease of Setup/Portability

PHP wins here, you don’t need write your own HTTP headers as you do with Python, more hosts support it, it’s easier to connect it to a database and there seem to be more tutorials on it.


I would say PHP community and Support is better but with days passing by i have noticed large Python community helping out.

Other Sources:

I liked may comparisons but few are very good i am listing the ones below, i will keep on adding when i get time.


I would prefer Python for the sake of developing a scalable application (its not like you can’t do in PHP), but its easier in Python. Moreover, Google supports Python with its Google App Engine where web sites can be hosted on Google’s server for free, it also supports Python frameworks like Django so my bet will be on Python. PHP on the other hand still have 60% of the market share and i bet with the new release (6.0) in the corner they will certainly fill up the gap by including namespaces,high level data types etc.

If you’ve got any thoughts, comments or suggestions for things we could add, leave a comment! Also please Subscribe to our RSS for latest tips, tricks and examples on cutting edge stuff.

New Heights for web applications

When it comes to programming, more specifically the development of web applications, it is important to consider all the tools of the trade before using the one that is going to be used for the job.

PHP is great. With the release at the time of PHP 4 and now its time for PHP 6. it’’s initial object functionality I started to get up to speed with many of the OOP principles. I was building some pretty amazing Content Management Systems, Digital Asset Management Systems, even Web Top Publishing Systems. My previous commitment to learn Java was fading as my experience grew with PHP was growing, seeing that I could build all the amazing things with what I had originally felt was a subordinate language.

We have search the performance for the PHP and many other languages like python,Perl,java,Vb,and finally ruby, below the difference between all the programming languages as graph which shows the future for the PHP.

Following graph shows the new lines of code in various languages in recent years


PHP dominates the new lines of code and only PHP and Ruby are on a steady curve upward.  Yeah – I know that “number of lines of code” is not a great measure, but none of these languages are overly verbose so it’s an interesting proxy metric.


Active developers tells a different story.  While PHP is growing a little relative to the others, they all seem to have a relatively flat curve.  The well known shortage of Ruby developers is reinforced by this data, as well as the next graph.


Comparison between all the programing language..

Does it prove anything?

This was the chart I found really interesting.  Ruby is clearly the trendy new language.  Given normal supply / demand lags, you’d expect that this is a leading indicator of a significant uptick for Ruby on the other two charts in 2007.  My conclusion is different than Robin’s – while PHP appears to be dominant today, the rapid growth in new projects in Ruby indicates that it is currently positioned as “the language of the next wave of applications.”  This is consistent with what I’m hearing and seeing from many new startups.


I suspect very few people will argue that PHP is a more elegant language or is more powerful than Ruby. Frankly, Ruby is probably may favorite language that I have ever worked with and I have worked with Classic ASP, ASP.NET, VB.NET, C#, Java, and Perl all rather extensively over the years. Ruby is both highly expressive and concise which is rare and refreshing.

Rails is a very comprehensive and effective web development Framework and there’s nothing exactly like it in PHP. You get a huge amount of functionality for free. Developing in Ruby on Rails is also a very fast process because Ruby is a very concise language requiring much less typing than any other language I’ve worked with. Code Igniter is a really nice PHP framework. It will give you a great boost when developing your next PHP application.

The hosting and deployment struggles with Ruby on Rails is a major sticking point for me though. As the owner of a web development company many of our smaller clients do not have the budget for their own VPS account and even if they did, we don’t have the staff to manage a large number of VPS accounts or dedicated servers. Keeping the security updates current, managing any issues that may occur with email, and all the other headaches that go along with managing your own VPS or Dedicated server is more than we care to take on for the relatively small, practical difference between PHP and Ruby. For large projects, it may be worth the trouble, but for small to medium sized projects, PHP is much easier to deploy, less expensive to host, and the language is capable of taking on everything those types of sites require. For our projects, development time with PHP is not noticeably longer than with Ruby on Rails. Ruby on Rails integrates a lot of things for the developer.

There is ActiveRecord for managing the link between models and the database, migrations for keeping development and live databases in sync, built in testing, the ajax – prototype javascript library is included, and you get a well defined file system structure. While it may not all be packaged together as well, PHP can do all of the above.

Thank you for reading this and I would love to read your comments! Also subscribe to our RSS.