Blog moved to pixelsspace.com

January 30, 2010 Leave a comment


Dear Visitors, The Blog has been moved to http://pixelsspace.com/. I have started my own Blog :) You can find the latest posts, and updates on my blog at pixelsspace.com.


Thank you
Suhail

Categories: post Tags: , ,

Python & The Editors

December 31, 2009 3 comments


To tell about python editor’s there are many editors available for python, like activetstate’s komodo, python wingware, Stani’s etc. The choice of text editor to choose depends upon you, the operating system you use, the number of features your require from your text editor, etc. Here I am writing my own list of text editors, that i have used. Theres also this good little article i found on about.com on “Choosing a Text Editor for Python Programming” http://python.about.com/od/gettingstarted/ss/text_editors.htm.


Geany: Geany is that little editor, i keep at hand for any purpose, whether i wanna write an article or do some coding stuff, i prefer to use geany most of the time, its simple and lightweight, to be honest, the main thing i started using geany is, it opens with all pages and tabs from where you had left, if you have shut down your computer and when you come back and start your computer, you start geany, and it will open up with all the tabs that you had left open to work upon. i couldn’t find this feature in any other editors i have used so far. And it also has lots of other features, to view the different features of Geany, you can visit this link Here.


Vim: vim for sysadmins they call it as vi, this is also one powerful editor, its a unix editor, it also has this plugin feature, you can configure to act as a python editor, and being a unix editor, comparatively its the most light-weight and has a lot of features that can configured as required. And if you want to get a good hands on vim and want to have a good knowledge about the editor, i suggest you read swaroopch’s “A Byte of Vim”, you will learn about the different features of vim and how it can be used and also how you can configure vim to be the editor of your choice. And you can also visit this link http://0xbabaf000l.blogspot.com/ it has lot of comic strips about vim, gnu and other stuff.


gedit: its the is the official text editor of the GNOME desktop environment. sure it is again a light-weight editor but, i won’t call it powerful and neither it has that many features, all i would say its a simple little editor that can get your work done, it sure has the plugins feature, for a list of its features visit the Gedits official website page here: http://projects.gnome.org/gedit/index.html





ActiveState Komodo Edit: Now here we come to the hard core editor, Komodo Edit supports PHP, Python, Ruby, Perl and Tcl, plus JavaScript, CSS, HTML and template languages like RHTML, Template-Toolkit, HTML-Smarty and Django. This is again one of my favorite editors after Geany, its not light-weight as the other editors i have mentioned till now, you can’t expect it to be a light-weight, as it has lots of features, Multi-language support, Project management, toolbox, Extensions, plugins, code snippets, html preview, etc. read the complete list of features here: http://www.activestate.com/komodo_edit/features/
And its available for linux as well as windows and Mac.


These are some of the editors that i have used so far for coding in python, these editors are free, there are other editors too like Stani’s python editor, pydev, Boa constructor, bluefish (never tried those) but i will still stick to Geany, as i have got used to it, and it has that one feature that i always wanted, of opening up with all the tabs from where you had left.

stepup2: Python

December 29, 2009 Leave a comment


posting after a long time, its been over 2 months since the last post. can’t help it, that’s the life of a sysadmin. ok, moving on to this post, as i have decided that i would be writing on mostly python, as that has become my favourite programming language. now after a long break, continuing back on my learning python journey, I have picked up this Book: Python for Unix and Linux system administration By Noah Gift and Jeremy Jones. I have still not completed the book, just reached the 4th chapter, but I am seriously liking it, After recommending Magnus Lie Hetland’s “Beginning python from novice to professional”, this is one another book that i would recommend for beginners as well as for any person wanting to learn python, its very well and clearly explained, and the one good thing, i liked is, lot of practical examples.


Please don’t be bored, To start with, Authors Acknowledgement, Yes!, I am mentioning this part, it might sound boring, why need to start with Acknowlegdement, If you look at Noah’s acknowledgement, its a very very long Thank’s giving list, But!, I liked it, that was something really humble, he has thanked each and every freind and mentor he has met, even his teachers at school, its really quite interesting.


Moving onto the next best part Chapter 1, “Introduction”, the question, Why Python?, I clearly agree to what the Author’s have explained about why to use python. Some reasons from the book that i would mention, Yes, Python is easy to learn. If a language can’t help you become productive pretty quickly, the lure of that language is severely diminished. Why would you want to spend weeks or months studying a language before you are able to write a program that does something useful? This is especially the case for sysadmins. If you can’t learn a language quickly enough to start writing scripts with it almost immediately, you should strongly question whether you should be learning it. However, a language that is easy to learn but doesn’t allow you to do fairly complex tasks isn’t worth much either. So the second reason to consider Python to be an
excellent programming language is that, while it lets you start simply, it also allows you to perform tasks that are as complex as you can imagine.


In this introduction part they have also taken some little examples and compared doing the same task in python and then doing the same thing in Perl and Bash and the difference between them. And there’s this little article called “Motivation”, this is a really good little article for people who are new to programming and are learning programming for the first time.


Then they move on to “The Basics”, here you will get to know about ipython, its features, benefits and how to use it, even i never knew there was something like ipython and really useful. along with ipython the chapter takes you further on functions in python and import statements in python and other basics.

Read more…

Django and The MVC pattern in web development

October 18, 2009 1 comment


django_logo1



Django is a web framework built in python, it enables you to build clean, feature-rich application in less amount of time.


Web development has made a lot of progress during the last few years. It began as a tedious task that involved CGI interfacing external programs with the web server. CGI applications used the standard I/O facilities available to the C programming language in order to get user input and produce the required page output. In addition to being difficult to work with, CGI required a seperate copy of the program to be launched for each requests , which quickly overloaded the servers.


Then, new scripting languages were introduced to the web development, and this inspired developers tocreate more efficient technologies. Languages such as Perl and PHP quickly made their way into the world of web development, and as a result common web tasks such as cooking handing, session management and text processing became easier. Although these scripting languages had the libraries, to deal with the day to day web tasks, they lacked unified frameworks, as libraries were fundamentally different in design, usage and conventions. Therefore, the need for cohesive frameworks arose.


Few Years Ago, The MVC (Model View Controller) was introduced to the world of web development for building of web based applications. This software engineering pattern seperates data(Model), user interface(View), and data handling logic(Controller), so that one can be changed without affecting the other. The Benefits are that designers can work on the interface without worrying about data storage and Management. And Developers can think and code on the logic of Data Handling without worrying about the presentation.

Now how does Python come into play ? Although python is used for build wide variety of applications, it is also very suited for web applications. It has a clean and elegant syntax and is supported by large library of modules which covers everything , from multi-threading to the zipping of files. Python laguage’s Object Oriented model is very well suited for the MVC style of web development.


As you can see performance is a very big concern with many of the web projects and it will always be with any of the new coming web projects. And in such situations, Python’s runtime environment does a very good job. as it is known to be fats and stable. Python supports wide range of web servers which include famous names like Apache, nginx, IIS, lighttpd, etc. Python also supports a wide range of Database servers, whch also includes some famous names like MySQL, PostGreSQL, etc. And if you are using Django framework, you don’t need to deal with the databases directly, Django provides a unified layer of access to all database engines.


Advantages of Python :-

Read more…

Apache: mod_python

October 18, 2009 Leave a comment


apache_logo



One of the most interesting ways to use python is the Apache’s mod_python module. The mod_python module actually embeds a fully functional python intrepreter inside the apache web server.
This is most frequently used as powerful means to generate dynamic web pages.


The most common method of generating dynamic web pages is the CGI script. A CGI page is invoked each time a given page is requested. It reads the request, generates a reply and then terminates. This mimics the operation of HTTP, which at its core, works with a single request at a time. The next time a request is received, the CGI script is again invoked from scratch. This design enables the CGI script to be both language and server neutral. indeed all popular web servers and programming languages support them.


However this compatibility comes at a price & performance, Starting up a CGI script is slow. There’s operating system overhead involved while creating a new process. There’s overhead from the python interpreter when initializing and loading the script. CGI script that connect to databases hit especially hard, since they must establish new database connection each time a page is displayed. For these reasons CGI scripts are not suitable for high traffic sites.


mod_python


The mod_python module is one answer to these problems. It actually embeds a full python interpreter inside the apache web server. your scripts are loaded only once per server process and only initialized then. Database connections can be established at the time of initialization and can be kept open throughout the life of web server process. whenever a page needs to be generated, a particular function is called, all data about the request is passed to it. This function has access to the environment created at the initialization time. so, for instance it can reuse the existing database connection.


while this scheme forces the use of apache web server, its advantage often outweigh its disadvantages, Read more…

python script: to change all the files extensions in a Directory

October 15, 2009 Leave a comment


a python script to change file extensions of all the files in a directory:


_____________________________________________________________________________________________


#!/usr/bin/env python
import os
import string

my_directory=’/home/ross’

for object in os.listdir(my_directory):
      if os.path.isfile(os.path.join(my_directory, object)):
              req_file=object
              if ‘.py’ in req_file:
                    ren_file=req_file.replace(‘.mp3′, ‘.mp4′)
                    old_file=os.path.join(my_directory, req_file)
                    new_file=os.path.join(my_directory, ren_file)
                    os.rename(old_file, new_file)


_____________________________________________________________________________________________


(Note:- Please take care of indentaion whenever writing a python script, The script posted above, may not be properly indented)

python script: to count the no. of lines in a file

October 15, 2009 Leave a comment


a simple script to count the no. of lines in a file:-


____________________________________________________________________________________________


#!/usr/bin/env python

read_file=open(‘/testfile.txt’, ‘rb’)

count_file=len(read_file.readlines())

print count_file


____________________________________________________________________________________________


(Note:- Please take care of indentaion whenever writing a python script, The script posted above, may not be properly indented)

Categories: Python Tags: , ,
Follow

Get every new post delivered to your Inbox.