Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - WSH in Other Languages
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

WSH in Other Languages
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2008-08-11

    Table of Contents:
  • WSH in Other Languages
  • VBScript
  • Jscript
  • Python
  • More Languages

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    WSH in Other Languages - Python


    (Page 4 of 5 )

    Python development began in the late 1980s; it was first published in 1991.  It is a high-level programming language that focuses on productivity rather than readability.  It supports multiple programming paradigms, automatic memory management, and has a large, comprehensive standard library. These features have led Python to become one of the most commonly used open-source environments.

    While Python is widely used in the Linux community, it is becoming more and more popular to Windows programmers as well. The feature-rich language helps bridge a gap between the two communities while offering a feasible open source solution to Microsoft’s proprietary languages. With increased support in the Windows community, Python is now gaining a lot of momentum as a viable alternative for WSH programming.

    The most commonly used Windows distribution is ActiveState’s ActivePython.  This free distribution offers the Python core, many popular extensions, and complete documentation.  It also includes PyWin32, a set of extensions that provides Python bindings to much of the Windows API, and the ActivePython installer adds support for use in the Windows Script Host environment.

    WSH will not automatically detect a script written in Python, so you will have to specify the Python engine when launching the script, as I explained earlier in this article.

    cscript //E:Python myscript.py

    The command line above can be used to launch a Python script in WSH.  You might also consider adding a unique file extension for Python scripts written in WSH.  I’ll show you how you can do that in part two of this series.

    fso = WScript.CreateObject("Scripting.FileSystemObject")

    You’ll have to use the WScript object’s CreateObject method to connect to COM objects. The WScript object is immediately available whenever a Python script is run in the WSH environment.

    folder = fso.GetFolder("C: emp")

    files = folder.Files

    Python’s object dot syntax should look refreshingly familiar when accessing an object’s properties and methods.

    Working with Collections

    Like VBScript, Python is able to work with collections and its simple For structure makes it easy to iterate through each of the collection’s objects.

    for file in files:

       print file.name

    You may use either the WScript object’s Echo method or Python’s native print command for outputting text to the screen.

    Additional Notes About Python

    Python does not require line endings and is pretty flexible about whitespace.  Case sensitivity is much like Jscript in that it does require objects to be case sensitive while their properties and methods are not.

    One caveat for Python users is that you cannot set an object’s property value directly. You must instead use the SetValue method as shown below.

    object.SetValue("property name", newvalue)

    Finally, a nice feature of Python is that it automatically imports all constants whenever you create an instance of an OLE object. These are created as properties of win32com.client.constants.

    win32com.client.constants.wdDoNotSaveChanges

    So any time that you create an instance of the Microsoft Word automation object, the above constant will be defined.

    More Windows Scripting Articles
    More By Nilpo


       · The Windows Script Host is not limited to VBScript and JScript. In fact, you can...
     

    WINDOWS SCRIPTING ARTICLES

    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...
    - Modifying XML Files in WSH
    - Reading XML Files in WSH
    - Visual Basic 2005 XML Programming Using XML ...
    - Creating an XML Document in WSH
    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT