analitics

Pages

Sunday, June 5, 2011

An alternative for parsing - the pyparsing module

First download the package from here, unzip and run the installation command:
C:\pyparsing-1.5.5>python setup.py install
running install
running build
running build_py
creating build
creating build\lib
copying pyparsing.py -> build\lib
running install_lib
copying build\lib\pyparsing.py -> C:\Python27\Lib\site-packages
byte-compiling C:\Python27\Lib\site-packages\pyparsing.py to pyparsing.pyc
running install_egg_info
Writing C:\Python27\Lib\site-packages\pyparsing-1.5.5-py2.7.egg-info
From the official site we find that:
The pyparsing module is an alternative approach to creating and executing simple grammars, vs. the traditional lex/yacc approach, or the use of regular expressions. The pyparsing module provides a library of classes that client code uses to construct the grammar directly in Python code.
The package comes with a number of examples that illustrate the flexibility of this module.
This file format is used by ICal on the Macintosh and in the Mozilla Calendar project. I think that can be imported into google calendar.

They can be found here.
Of these I particularly liked the example for parsing files with extension ics.

Thursday, April 21, 2011

Python and Merlin , using win32com module.

I remembered my days when I played with visual script.
Later I discovered python on linux and I realized that it's as good if not better.
Then I made ​​a script that display the character Merlin said something.
Today I'll try the same thing with python.
First you have to install python module called win32com.
For this we use installer from here.
It automatically installs python 2.6 folder, see picture below...
To begin to build script.
For this we need to read the MSDN documentation least, see here.
The first step required is to import module module ...
import win32com
from win32com import client
from win32com.client import constants
Access file .acs and declare a variable named vrajitor to use it.
agent = win32com.client.Dispatch("Agent.Control.2")
agent.Connected = -1
agent.Characters.Load("Merlin", "Merlin.acs")
vrajitor= agent.Characters("Merlin")
Now we can use its methods for animation and not only ...
vrajitor .LanguageID = 0x409
vrajitor .Show()
vrajitor .Play("Announce")
vrajitor .Speak("I like to use Python programming language!")
vrajitor .Speak("... and I'm really good. See!?")
vrajitor .Play("Congratulate")
print "Type some commands! (max 99 comands)"
print "Congratulate, Acknowledge, Blink, Confused, Decline, Explain"
for i in range(100):
 cmd=raw_input()
 print cmd
 vrajitor .Play(cmd)
Here's the result ...

merlin python from Catalin Festila on Vimeo.