Python vs .Net

Etienne Charland mystery at golden.net
Sun Jan 5 01:40:25 EST 2003


I would like to compare Python with .Net. First of all, for those who knows
.Net, what are the pros and the cons of each? Secondly, how would I write
this simple database application in Python, to see how it looks like. I've
written the code required to do it in VB.Net.

Let's say I have a window containing a ComboBox and a TextBox. At program
load time, I get data from a database. I get those fields: "ID", "Code",
"gNom". The ComboBox must contain the list of clients, showing the "Code"
field . But I also must be able to get the associated ID of the selected
item. And the items have to be sorted. When I select a client, the field
"gNom" has to be displayed in the textbox, for the selected client.

Here's the code of the window. Note that all the bindings can be done with
the designer.
-------------------------------------------------
Imports System.Data.SqlClient
Public Class Form1
    Inherits System.Windows.Forms.Form
'Removed Windows Forms Designer generated code

    Private Const ConnectionString As String = "data source=(local);initial
catalog=GipelData;integrated security=SSPI;persist security info=False"
    'Contains the in-memory data. xmlGeneral is a typed dataset. Do you
    'really need to know what is a typed dataset? Just to give you a hint, I
can
    'write   myDataSet.Clients   instead of    myDataSet.Tables("Clients")
    Private myDataSet As New xmlGeneral

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        'Sort the data
        myDataSet.Clients.DefaultView.Sort = "Code"

        'Fill the DataSet
        Dim myConnection As New SqlConnection(ConnectionString)
        Dim myDataAdapter As New SqlDataAdapter("SELECT ID, Code, gNom FROM
Clients", myConnection)
        myDataAdapter.Fill(myDataSet.Clients)

        'Bind the controls to the in-memory data
        ComboBox1.DataSource = myDataSet.Clients
        ComboBox1.DisplayMember = "Code"
        ComboBox1.ValueMember = "ID"

        'Since the datasource for this binding is the same as for the
        'combobox, it will automatically display the data of the
        'selected item
        TextBox1.DataBindings.Add("Text", myDataSet.Clients, "gNom")
    End Sub
End Class
-------------------------------------------------

How do you write it in Python?






More information about the Python-list mailing list