Here is some examples on how to use ADO with Python.
Very useful article
Thanks Little Python
http://mail.python.org/pipermail/python-list/2006-February/368208.html
Thursday, January 24, 2008
Sunday, January 20, 2008
ASP.NET - IronPython
It's now possible to use IronPython in Visual Web Developpement Express Edition 2008.
If you are wondering does it worth to switch to IronPython.
Look at this server side part, and compare it with the traditionals languages used
Server Side:
Client Part:
If you are wondering does it worth to switch to IronPython.
Look at this server side part, and compare it with the traditionals languages used
Server Side:
def Page_Load(sender, e):
pass
def onClickButton1(s,e):
color = result.InnerHtml = TextBox1.Text
result.Style.set_Value("background-color:%s;"%color)
def Menu1_MenuItemClick(s,e):
result.Style.set_Value("background-color:red")
choice = Menu1.SelectedValue
result.InnerHtml = choice
Client Part:
<%@ Page Language="IronPython" CodeFile="Default.aspx.py" Inherits="Microsoft.Web.Scripting.UI.ScriptPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" OnMenuItemClick="Menu1_MenuItemClick">
<Items>
<asp:MenuItem Text="Fichier" Value="Fichier"></asp:MenuItem>
<asp:MenuItem Text="About" Value="About"></asp:MenuItem>
</Items>
</asp:Menu>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="onClickButton1" />
<div id="result" runat="server">
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Friday, January 18, 2008
Boo on .Net
What language choose for .Net : C# VB.NET IronPython ?
Although my language of choice is Python, I must admit
that Boo is very attractive.
It does not have the verbosity of VB.NET or C# and it's syntax
is greatly inspired by Python.
Take a look at this presentation :
http://www.infoq.com/articles/boo-intro
Although my language of choice is Python, I must admit
that Boo is very attractive.
It does not have the verbosity of VB.NET or C# and it's syntax
is greatly inspired by Python.
Take a look at this presentation :
http://www.infoq.com/articles/boo-intro
Sunday, December 30, 2007
XUL and Python
You can use Python with XUL with the help of a http server
which execute plain Python Scripts sent by the client.
Like the following :
CPython Server
<?xml version="1।0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="example-window" title="Example 7.2.1"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script language="javascript">
var wmi=" \n\
import wmi \n\
c = wmi.WMI('Python') \n\
for os in c.Win32_OperatingSystem(): \n\
caption = os.Caption \n\
response = caption \n\
filename = 'foo'"
function WebMethod(url,request,callback)
{
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
} catch (e) {
alert("Permission UniversalBrowserRead denied.");
}
var http = new XMLHttpRequest();
var mode = request?"POST":"GET";
http.open(mode,url,true);
if(mode=="POST"){http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');}
http.onreadystatechange=function(){if(http.readyState==4){callback(http.responseText);}};
http.send(request);
}
function CallBack(r)
{
alert(r);
}
</script>
<box id="aBox" width="200">
<button label="GetOsName" oncommand="WebMethod('http://127.0.0.1:9981',wmi,CallBack);"/>
</box>
</window>
which execute plain Python Scripts sent by the client.
Like the following :
CPython Server
<?xml version="1।0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="example-window" title="Example 7.2.1"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script language="javascript">
var wmi=" \n\
import wmi \n\
c = wmi.WMI('Python') \n\
for os in c.Win32_OperatingSystem(): \n\
caption = os.Caption \n\
response = caption \n\
filename = 'foo'"
function WebMethod(url,request,callback)
{
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
} catch (e) {
alert("Permission UniversalBrowserRead denied.");
}
var http = new XMLHttpRequest();
var mode = request?"POST":"GET";
http.open(mode,url,true);
if(mode=="POST"){http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');}
http.onreadystatechange=function(){if(http.readyState==4){callback(http.responseText);}};
http.send(request);
}
function CallBack(r)
{
alert(r);
}
</script>
<box id="aBox" width="200">
<button label="GetOsName" oncommand="WebMethod('http://127.0.0.1:9981',wmi,CallBack);"/>
</box>
</window>
Thursday, December 27, 2007
WMI - Mochikit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
table.prettytable thead,th,tfoot
{
background-color : #676789;
text-align : center;
font-weight: bold;
color: #fff;
}
table.prettytable
{
border: 1px solid black;
}
</style>
<script type="text/javascript" src="../../lib/MochiKit/MochiKit.js"></script>
<script type="text/javascript">
result = []
row_display = function (row)
{
return TR(null, map(partial(TD, null), row));
}
function getDiskInfo()
{
var loc = new ActiveXObject("WbemScripting.SWbemLocator");
var wmi = loc.ConnectServer("", "root\\cimv2");
var ins = wmi.ExecQuery("select * from Win32_LogicalDisk");
for (var col = new Enumerator(ins);!col.atEnd();col.moveNext())
{
var disq = col.item()
result.push([disq.DeviceId,disq.FreeSpace,disq.Size])
}
var newTable = TABLE({'class': 'prettytable'},
THEAD(null,row_display(["Name", "FreeSpace", "Size"])),
TFOOT(null,row_display(["foot1", "foot2", "foot3"])),
TBODY(null,map(row_display, result)));
appendChildNodes("theBody",newTable);
}
</script>
</head>
<body id="theBody" onload="getDiskInfo()">
</body>
</html>
Powered by ScribeFire.
Wednesday, December 26, 2007
wmi - IronPython
import System
import clr
clr.AddReference("System.Management")
import System.Management
def requestWMI(squery,sproperties):
output = ""
objMgt = System.Management.ManagementObjectSearcher(squery)
for result in objMgt.Get():
output += result.GetPropertyValue(sproperties)
return output
print requestWMI("Select * from Win32_BIOS", "Caption")
raw_input()
Powered by ScribeFire.
Tuesday, December 18, 2007
JScript .NET + WMI
Finding documentation for using WMI with JScript is not easy.
Compile this code with 'jsc' (shipped with .Net) in an exe file
import System;
import System.Management;
var diskSearch = new ManagementObjectSearcher("Select * from Win32_LogicalDisk")
var obj = diskSearch.Get()
var prop = new Object()
for (prop in obj){
print(prop['Caption'])
}
Compile this code with 'jsc' (shipped with .Net) in an exe file
import System;
import System.Management;
var diskSearch = new ManagementObjectSearcher("Select * from Win32_LogicalDisk")
var obj = diskSearch.Get()
var prop = new Object()
for (prop in obj){
print(prop['Caption'])
}
Powered by ScribeFire.
Subscribe to:
Posts (Atom)