jump to navigation

Overcoming the fear of Python January 16, 2008

Posted by xk0der (aka Amit Singh) in : Programming and software development, Random musings , 6comments

As all C, C++ and Perl devotees, I too looked upon Python with apprehension. Python? What? I asked. The very idea of white-spaces being part of syntax gave me jitters and I convulsed with disgust. Why Python? Perl can do it. OOP? Perl has it … errm .. Kind of.

After reading numerous articles about python by putting the search terms “I hate pyton“, “python will die” and the like, I started getting a grasp of differences and likeness between python and other languages. One thing more I learned was, never be judgmental about a programming language if you have not used it. So after traversing threads at various forums related to “Love Python” and “Hate Python” I started understanding the various mumbo-jubo related to python. And then the thought occured to me, let’s give it a try. I downloaded python on my Windows XP machine at home and Vim for windows. Then jumped right into coding a problem that was asked to me in an interview. It was a design problem actually, but nevertheless a design can be implemented :) .

Within minutes I was automatically indenting code as I used to with C,C++ or Perl (or other free form languages I had used, for that matter). So the frown over mandatory white-spaces soon turned into a smile. And by the time I could realize I was finished creating a four road junction traffic simulator. I did searched the net for some reference, but the best thing was I just looked at the example and understood what it was, no reading what the code does or will do. Other syntax came so naturally that I didn’t even had to look online. That is I guess the beauty of Python.

In around half an hour or so, I had a complete running program in Python, using classes, random number, lists and other subtle features. The code was so readable, I thought, do I need some of those comments I’ve put in there? Some were required. But most of the time the code was itself very much self-explanatory.

Later I booted my laptop (it has FC7 installed) and copied the code on my Lappy. Python comes bundled with FC7 so I straight-away executed the code. Wow! … Its faster than windows .. Ha ha … yes this is what I noticed. Then I tinkered a bit more with the code, optimizing some things and learning new stuff in the process. Overall I enjoyed my first step into Python, very much.

I’m not going to shun C,C++ or Perl for that matter. For quick one-liners Perl is still the best. My domain is embedded systems and Linux Kernel programming so C and C++ are essential. But this discovery about Python has really give me an option. Option to create large and manageable programs in less time. They say in the python community, You spend more time solving the problem as you code and less time worrying about the language and its syntax. I Agree!

Like this post?

VMWare - Simple communication between Host and Guest January 2, 2008

Posted by xk0der (aka Amit Singh) in : Tips and tricks , 1 comment so far

Recently I’ve been working on a project which required VMWare as one of the component. As part of this project some sort of communication, albeit simple in nature,was required between the host and the guest machine.

Here are two simple commands, one to be run on host and one on the guest, using which you can pass simple information between the host and the guest virtual machine.

(single line command may wrap to next line … please note this)

Host machine commands:

Syntax:
$ vmware-cmd <path-to-machine.vmx> getguestinfo <variable>
$ vmware-cmd <path-to-machine.vmx> setguestinfo <variable> <value>

Example:
$ vmware-cmd /vmware-stuff/Ubuntu.vmx setguestinfo some_counter 12
$ vmware-cmd /vmware-stuff/Ubuntu.vmx getguestinfo some_counter

The first command, above, will set variable ’some_counter’ to value ‘12′ and the second one will fetch the value of ’some_counter’ on/from the virtual machine specified by /vmware-stuff/Ubuntu.vmx

VMWare typically identifies different virtual machines by their configuration files (.vmx)

To set/get info from other machine use the configuration file path of that virtual machine.

The above variables may be accessed on the guest (Virtual machine), in our case Ubuntu.vmx using the commands shown below (see example).

And yes! make sure the Virtual machine is powered on :)
Guest machine commands:

Syntax:
$ vmware-guestd --cmd 'info-set guestinfo.<variable> <value>'
$ vmware-guestd --cmd 'info-get guestinfo.<variable>'

Example:
$ vmware-guestd --cmd 'info-set guestinfo.some_counter 35'
$ vmware-guestd --cmd 'info-get guestinfo.some_counter'

Variables set in Virtual Machine (Guest) may be accessed on Host and vice-versa.

I tested this on VMWare-Server as it is free :) … hopefully and very likely the same is applicable for VMWare-Workstation.

For more hardcore scripting, you may Use Perl-SDK provided by VMWare (On windows you may use COM-SDK).

Please leave comments if you found this info helpful (or even otherwise).

- xk0der

Like this post?