Thursday, April 09, 2009

I envy Python programmers

I've sort of settled with a programming language I generally use, C#. I know other languages too, and sometimes I wish I did more Python programming. Python really simplifies programming. As an example, I coded an application recently that automated pushing form values to a web page. In C# 3.0, the code would look like this:


using System.Collections.Specialized;
using System.Net;
//...
var formData = new NameValueCollection { { "Var1", "Value1}, {"Var2", "Value2"}};
var webClient = new WebClient();
webClient.UploadValues("http://localhost/localapp.aspx", formData);

In Python 2.X, the code would look like this:


import urllib
#...
formData = urllib.urlencode({ "Var1" : "Value1", "Var2" : "Value2"})
urllib.urlopen("http://localhost/localapp.aspx", formData)

There's no error handling or anything special in this. This example is rather contrived, to be completely fair, but when you add other things like multivariable assignment, and take into consideration Python's standard library, you might understand why I'm envious. Ah well

No comments: