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

Monday, January 11, 2010

Unloading DLLs in Python through CTYPES

How can I unload a DLL using ctypes in Python? - Stack Overflow discusses the issues related to unloading a DLL which has been loaded using ctypes in Python


Saturday, January 9, 2010

A Techie Tech Writer Blog � Single-sourcing Training Exercises with Sphinx

A Techie Tech Writer Blog � Single-sourcing Training Exercises with Sphinx shows a nice example of how to use Sphinx to generate training exercises from Python source files.

Thursday, October 1, 2009

PyCon India 2009 My impressions

I attended 1st day (26 September 2009) of the PyCon India 2009 conference. It was first Python Conference in India and I felt inclined enough to go all over to Bangalore from my home place Noida and attend the conference.

The conference was organized at IISc Bangalore. From the main gate to reach the conference area was easy as proper directions had been placed all over. Registration was a bit chaotic. There were not enough desks to handle the huge crowd waiting to be registered. I guess it was still quite satisfactory process considering the fact that it was first such event in India and there were not enough funds (I guess) to manage the event professionally. Since I had pre-registered, I had to pay just 200 rupees for attendance. They provided us with schedule, a T shirt, a notebook, a pen and off course a badge which was quite good as a conference kit. And the lunch and tea breaks were excellent.

There were about 600+ delegates participating in the conference. The profile varied between students, professors, independent consultants, professional programmers etc.

The first session by Prabhu Ramchandran (My adventures) was quite nice. It was interesting to see how an open source project Mayavi had been run successfully over the years out of India. Since there were three parallel tracks going on, hence I had to identify the sessions I wished to attend.

Some of the sessions had a lot of issues related to presentation. The presentation on zc.buildout was quite boring. The presenter spent too much time just discussing what is isolation and repeatability that there wasn't much time left for actual demonstration. Similarly, the session on DJango turned out to be quite boring. There were three presenters taking turns in the talk. They spent a lot of time preaching about DJango, like what it is, why it is great, etc. etc. They also spend a lot of time typing the code which they wished to demonstrate. I guess one should be very careful in using the 45 minutes available during a conference time and make the best use of it as possible. One should avoid time wasters like typing code and fixing bugs during the talk itself. Another boring session was on Semantic web. The presenter was explaining a whole lot of difficult concepts. It seemed like a typical IIT lecture in which students preferred to sleep through or if possible bunk them.

Another interesting talk was 'Jython at Strand LS' by Janaki where the speaker explained how they used Jython at their company. Examples were short and sweet. Illustrations were easy to understand and the speaker had a great sense of humour. I was impressed to see the extensive application of Jython in a production quality platform like AVADIS (TM) at Strand.


Finally, my own talk on using ZPT and RML for generating PDF in Python applications came. I didn't expect too many to attend the talk but I was happy to see about 30+ ppl still continuing to sit for my session. Some of them left during the session which meant that they didn't really enjoy the content much. Others continued through the session and I guess they liked what I talked. I would leave it for others to comment on how good the session was.

There were tracks for lightning talks but I guess very few speakers were actually prepared to conduct them. There were lots of talks registered but ultimately many of them were not delivered.


Some of the things I feel that should be improved for future conferences:

  • Expected audience of a talk should be more clearly explained
  • Focus should be more on specific coding workshops rather than general talks
  • Longer workshops on specific topics should be conducted if there are speakers available
  • There was no peer review of presentation material. This should be extensively fixed.
  • The work on presentation materials should actually finish 2-3 months before the conference at least so that peer reviews and revisions can be completed say about 2 weeks before actual conference.
  • Scheduling of talks should happen through a more transparent process
  • Registered delegates should receive notifications about talks (when its announced, when presentation materials are uploaded etc.) over mail as the process keeps on going before the actual conference
  • The talks without presentation material should be rejected in the final schedule.
  • Speakers should avoid wasting too much time talking about abstract concepts and spend more on illustrations. They should also avoid typing code during the session.
  • Multi-speaker talks should be minimized

Wednesday, November 5, 2008

Zope 3 Views as multi-adapters

This diagram shows how Zope Views are implemented as multi-adapters. Student is a content class which implements IStudent interface. HTTPRequest objects are created when an HTTP request (either through Web browsers, or through XML-RPC calls) is made. StudentView is an adapter which adapts a Student object along with an HTTPRequest object and implements IBrowserView interface.

The diagram is not accurate reflection of design of browser views in Zope. It is just for demonstration of the idea of multi-adapters.
Posted by Picasa

Sunday, September 28, 2008

Cron in Python

Cron jobs are traditional time based scheduling service on Unix platforms. For an introduction to cron jobs, go to: http://en.wikipedia.org/wiki/Crontab

At times, different software solutions may need to incorporate cron like functionality. I ended up doing the same recently. As usual, I first tried to find out if there are any existing implementations of cron available so that I do not have to re-invent the wheel again. I was looking for a Python based implementation and found the following: http://sourceforge.net/projects/pycron/ (Python Cron, Great Cron for Windows).

Although the title mentions Windows but the implementation can work on any Python based environment. The software is GPL licensed. Its a small and simple implementation of Cron in Python. The solution is easy to read and understand. It helped me understand some of the intricacies of cron implementation (like matching the cron table information with current time, taking care of system clock issues, etc.).

The algorithm is based on the initial simple implementation of cron by Brian Kernighan.
  1. Read the cron file
  2. Determine if any commands are to be run at the current date and time and if so, run them.
  3. Sleep for one minute
  4. Repeat from step 1.

Friday, August 8, 2008

SVN configuration file

Lot of people like me don't know about a configuration file in subversion on the client side which can help in setting up a lot of default options for them. It took me a time to figure it out, so I guess its worth talking about.

The file resides at: %APPDATA%\Subversion\config on Windows systems.

Some of the uses of this file are:
  • Identifying different file extensions which should be ignored by default
  • Identifying different file extensions for which svn:eol-style=native can be set by default.

Working with the SubVersion Config file

In the following I will show you some examples of how you can use this config file to make your life easier.

Global Ignores

Typically when I work on my python projects, a number of *.pyc files are generated when Python compiles my source files. It is annoying to see them listed whenever I run svn update or svn status commands. Fortunately one can specify a set of file name patterns (typically wild-card based) which will be ignored by default.

In your configuration file:

  • Search for a line with keyword global-ignores
  • If the line is commented, un-comment it
  • add a list of file patterns which you wish to ignore

On my side it looks like:

global-ignores = *.o *.lo *.la *.pyc *.obj .DS_Store

VC++ programmers may like to add *.obj, *.exe, *.lib, *.dll etc.

Auto Props

SVN allows you to set some properties on the files. Some of the commonly used ones are svn:externals, svn:eol-style, svn:keywords etc.

I work on multiple platforms (Windows/Mac/Linux). Hence I usually need to check-in my source code with svn:eol-style=native so that when it is checked out on different platforms, the end of line characters are adjusted accordingly. (Read more about it in SubVersion manual).

My problem was that I had to do this manually for each file. Later on I found that its possible to specify in the configuration file a few automatic properties which get attached to a new file the moment its added to SVN repository.

  • Find out a line which has enable-auto-props
  • Make sure its un-commented
  • Make sure that it looks like: enable-auto-props=yes
  • Find out a section [auto-props]
  • For each file pattern of your interest (*.c, *.cpp, *.py), define the automatic properties which you would like to be setup. e.g.: *.py = svn:eol-style=native;svn:keywords=Id
  • You are done!!!

SubClipse and SVN

SubClipse supports two different SVN interfaces. JavaHL and SVNKit. JavaHL uses the same configuration files as the command-line client viz. %APPDATA%\Subversion\. SVNKit caches information in Eclipse keyring. I don't know much about it and won't talk about it. I am happy with JavaHL SVN interface for SubClipse.

I hope this post is useful to SubVersion users around the world.